Decompiled source of LethalCompanyMod v1.18.2

BepInEx\plugins\LethalCompanyMod\LethalCompanyMod.dll

Decompiled 5 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LethalCompanyMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalCompanyMod")]
[assembly: AssemblyTitle("LethalCompanyMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LethalCompanyMod
{
	[BepInPlugin("anton.lethalcompanymod", "LethalCompanyMod", "1.18.2")]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class AnimatedSlashSprite
		{
			internal Transform Transform;

			internal Renderer Renderer;

			internal Vector3 Anchor;

			internal Vector3 Drift;

			internal Vector3 BaseScale;

			internal Color Tint;

			internal float Phase;

			internal float Speed;

			internal float Roll;

			internal bool CameraAttached;
		}

		private sealed class SoulMeterVisual
		{
			internal GameObject Root;

			internal Image Fill;

			internal Transform Target;
		}

		private sealed class HiddenTerrainState
		{
			internal Behaviour Terrain;

			internal bool WasEnabled;
		}

		private sealed class ArenaEntityState
		{
			internal Vector3 Position;

			internal Quaternion Rotation;

			internal Vector3 Velocity;

			internal Vector3 AngularVelocity;
		}

		private class NetworkDomainSession
		{
			internal ulong Id;

			internal DomainKind Domain;

			internal Vector3 SourceCenter;

			internal Vector3 ArenaCenter;

			internal ulong CasterId;

			internal float Duration;

			internal readonly Dictionary<int, Vector3> Participants = new Dictionary<int, Vector3>();
		}

		private sealed class HostDomainSession : NetworkDomainSession
		{
			internal float TimeLeft;

			internal float OpeningTimeLeft = 2.35f;

			internal float OpeningEndRealtime;

			internal float EndRealtime;

			internal float EffectTimeLeft;

			internal float GambleTimeLeft;

			internal bool ArenaActivated;

			internal readonly HashSet<ulong> ParticipantClientIds = new HashSet<ulong>();

			internal readonly Dictionary<EnemyAI, ArenaEntityState> EnemyStates = new Dictionary<EnemyAI, ArenaEntityState>();

			internal readonly Dictionary<EnemyAI, float> EnemySpeeds = new Dictionary<EnemyAI, float>();

			internal readonly Dictionary<GrabbableObject, ArenaEntityState> ItemStates = new Dictionary<GrabbableObject, ArenaEntityState>();

			internal readonly Dictionary<NetworkObject, ArenaEntityState> NetworkEntityStates = new Dictionary<NetworkObject, ArenaEntityState>();

			internal readonly Dictionary<ulong, float> PlayerSoulValues = new Dictionary<ulong, float>();

			internal readonly Dictionary<EnemyAI, float> EnemySoulValues = new Dictionary<EnemyAI, float>();

			internal readonly HashSet<ulong> SoulDeathsSent = new HashSet<ulong>();
		}

		private enum DomainKind
		{
			InfiniteVoid,
			MalevolentShrineOpen,
			MalevolentShrineClosed,
			IdleDeathGamble,
			SelfEmbodimentOfPerfection
		}

		private enum DomainInputCommand
		{
			ToggleMenu,
			Select1,
			Select2,
			Select3,
			Select4,
			Select5,
			Confirm,
			Direct1,
			Direct2,
			Direct3,
			Direct4,
			Direct5
		}

		private readonly struct DomainStyle
		{
			public readonly Color BoundaryColor;

			public readonly Color CoreColor;

			public readonly Color AccentColor;

			public readonly Color LightColor;

			public readonly Color FogColor;

			public readonly Color TextColor;

			public readonly float LightIntensity;

			public DomainStyle(Color boundaryColor, Color coreColor, Color accentColor, Color lightColor, Color fogColor, Color textColor, float lightIntensity)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0028: Unknown result type (might be due to invalid IL or missing references)
				BoundaryColor = boundaryColor;
				CoreColor = coreColor;
				AccentColor = accentColor;
				LightColor = lightColor;
				FogColor = fogColor;
				TextColor = textColor;
				LightIntensity = lightIntensity;
			}
		}

		public const string PluginGuid = "anton.lethalcompanymod";

		public const string PluginName = "LethalCompanyMod";

		public const string PluginVersion = "1.18.2";

		private const float DomainDuration = 30f;

		private const float IdleDeathGambleMinDuration = 45f;

		private const float IdleDeathGambleMaxDuration = 70f;

		private const float OpeningDuration = 2.35f;

		private const float DomainRadius = 26f;

		private const float MalevolentShrineOpenRadius = 55f;

		private const int MalevolentShrineOpenDamage = 3;

		private const float ForcedJackpotChance = 0.065f;

		private const float EffectInterval = 0.35f;

		private const float ClosedBarrierRadius = 23.4f;

		private const float SelfEmbodimentInteriorScale = 1.5f;

		private const float BarrierReturnOffset = 1.5f;

		private const float InfiniteVoidMovementMultiplier = 0.015f;

		private const float JackpotDuration = 100f;

		private const float JackpotRegenInterval = 0.1f;

		private const int JackpotRegenHealAmount = 32;

		private const int JackpotMinimumHealth = 92;

		private const ulong NoJackpotRegenClientId = ulong.MaxValue;

		private const float GambleSpinInterval = 4.2f;

		private const float DomainRequestRetryInterval = 1.5f;

		private const int MaxDomainRequestAttempts = 4;

		private const float ArenaFloorSize = 62f;

		private const float ArenaCaptureRadius = 26f;

		private const float ArenaSafeSpawnHeight = 0.7f;

		private const float ArenaFallRecoveryDepth = 1.25f;

		private const float ExteriorBarrierPostTeleportDelay = 0.2f;

		private const float MaximumSoul = 100f;

		private const float MinimumSoulDrainPerSecond = 2.75f;

		private const float MaximumSoulDrainPerSecond = 20f;

		private const float SoulDrainFalloffDistance = 14f;

		private const float SoulExileDepth = 1500f;

		private const string OpenDomainMessage = "LethalCompanyMod.OpenDomain";

		private const string RequestDomainMessage = "LethalCompanyMod.RequestDomain";

		private const string CloseDomainMessage = "LethalCompanyMod.CloseDomain";

		private const string GambleRollMessage = "LethalCompanyMod.GambleRoll";

		private const string ShrineDamageMessage = "LethalCompanyMod.ShrineDamage";

		private const string DomainDeniedMessage = "LethalCompanyMod.DomainDenied";

		private const string DomainConfigMessage = "LethalCompanyMod.DomainConfig";

		private const string SoulStateMessage = "LethalCompanyMod.SoulState";

		private const string SoulDeathMessage = "LethalCompanyMod.SoulDeath";

		private readonly Dictionary<EnemyAI, float> originalEnemySpeeds = new Dictionary<EnemyAI, float>();

		private readonly Dictionary<DomainKind, AudioClip> domainSounds = new Dictionary<DomainKind, AudioClip>();

		private readonly HashSet<DomainKind> missingSoundWarnings = new HashSet<DomainKind>();

		private readonly Dictionary<ulong, int> domainUsesConsumedThisMoon = new Dictionary<ulong, int>();

		private ConfigEntry<int> domainUsesPerMoonConfig;

		private ConfigEntry<bool> infiniteDomainUsesConfig;

		private AudioClip? slotRollClip;

		private AudioClip? jackpotSoundClip;

		private AudioClip? selfEmbodimentOpeningClip;

		private Texture2D? infiniteVoidGalaxyTexture;

		private Texture2D? infiniteVoidBlackHoleTexture;

		private Texture2D? infiniteVoidInkTexture;

		private Texture2D? infiniteVoidStreakTexture;

		private Texture2D? malevolentShrineOpenBarrierTexture;

		private Texture2D? malevolentShrineClosedBarrierTexture;

		private Texture2D? idleDeathGambleBarrierTexture;

		private Texture2D? malevolentShrineGroundSealTexture;

		private Texture2D? malevolentShrineSlashTexture;

		private Texture2D? malevolentShrineSlashCoreTexture;

		private Texture2D? softParticleTexture;

		private readonly List<Transform> infiniteVoidRotators = new List<Transform>();

		private readonly List<LineRenderer> infiniteVoidPulseLines = new List<LineRenderer>();

		private readonly List<ParticleSystem> infiniteVoidParticleSystems = new List<ParticleSystem>();

		private readonly List<float> infiniteVoidParticleRates = new List<float>();

		private readonly List<RawImage> infiniteVoidOverlayImages = new List<RawImage>();

		private readonly List<RectTransform> infiniteVoidOverlayRects = new List<RectTransform>();

		private readonly List<LineRenderer> malevolentShrineSlashLines = new List<LineRenderer>();

		private readonly List<float> malevolentShrineSlashPhases = new List<float>();

		private readonly List<float> malevolentShrineSlashSpeeds = new List<float>();

		private readonly List<float> malevolentShrineSlashWidths = new List<float>();

		private readonly List<AnimatedSlashSprite> malevolentShrineSlashSprites = new List<AnimatedSlashSprite>();

		private readonly List<Transform> openingRotators = new List<Transform>();

		private readonly List<float> openingRotationSpeeds = new List<float>();

		private readonly List<ParticleSystem> openingTimedParticles = new List<ParticleSystem>();

		private readonly List<float> openingParticleStopProgress = new List<float>();

		private readonly List<Transform> idleDeathGambleRotators = new List<Transform>();

		private readonly List<float> idleDeathGambleRotationSpeeds = new List<float>();

		private readonly List<Vector3> idleDeathGambleRotationAxes = new List<Vector3>();

		private readonly List<Renderer> idleDeathGambleChaseLights = new List<Renderer>();

		private readonly List<Vector3> idleDeathGambleChaseScales = new List<Vector3>();

		private readonly Dictionary<Renderer, bool> hiddenDomainRenderers = new Dictionary<Renderer, bool>();

		private readonly Dictionary<Light, bool> hiddenDomainLights = new Dictionary<Light, bool>();

		private readonly List<HiddenTerrainState> hiddenDomainTerrains = new List<HiddenTerrainState>();

		private readonly Dictionary<DomainKind, GameObject> persistentDomainArenas = new Dictionary<DomainKind, GameObject>();

		private readonly List<NavMeshDataInstance> persistentArenaNavMeshes = new List<NavMeshDataInstance>();

		private readonly List<NavMeshData> persistentArenaNavMeshData = new List<NavMeshData>();

		private readonly Dictionary<EnemyAI, ArenaEntityState> arenaEnemyStates = new Dictionary<EnemyAI, ArenaEntityState>();

		private readonly Dictionary<GrabbableObject, ArenaEntityState> arenaItemStates = new Dictionary<GrabbableObject, ArenaEntityState>();

		private readonly Dictionary<NetworkObject, ArenaEntityState> arenaNetworkEntityStates = new Dictionary<NetworkObject, ArenaEntityState>();

		private readonly Dictionary<int, Vector3> domainParticipantSourcePositions = new Dictionary<int, Vector3>();

		private readonly Dictionary<ulong, HostDomainSession> hostDomainSessions = new Dictionary<ulong, HostDomainSession>();

		private readonly Dictionary<ulong, NetworkDomainSession> knownDomainSessions = new Dictionary<ulong, NetworkDomainSession>();

		private readonly Dictionary<ulong, GameObject> domainExteriorRoots = new Dictionary<ulong, GameObject>();

		private readonly HashSet<ulong> pendingExteriorBarrierSessions = new HashSet<ulong>();

		private readonly Dictionary<ulong, GameObject> sessionDomainArenas = new Dictionary<ulong, GameObject>();

		private readonly Dictionary<DomainInputCommand, InputAction> domainInputActions = new Dictionary<DomainInputCommand, InputAction>();

		private readonly Dictionary<DomainInputCommand, bool> domainInputLatches = new Dictionary<DomainInputCommand, bool>();

		private readonly Dictionary<ulong, float> localPlayerSoulValues = new Dictionary<ulong, float>();

		private readonly Dictionary<ulong, float> localEnemySoulValues = new Dictionary<ulong, float>();

		private readonly Dictionary<EnemyAI, float> localDirectEnemySoulValues = new Dictionary<EnemyAI, float>();

		private readonly Dictionary<ulong, SoulMeterVisual> playerSoulMeters = new Dictionary<ulong, SoulMeterVisual>();

		private readonly Dictionary<ulong, SoulMeterVisual> enemySoulMeters = new Dictionary<ulong, SoulMeterVisual>();

		private Renderer? infiniteVoidGalaxyRenderer;

		private Renderer? activeDomainInteriorRenderer;

		private Transform? shrineMouthRoot;

		private GameObject? shrineCameraVfxRoot;

		private GameObject? domainCameraBackdropRoot;

		private bool atmosphereCaptured;

		private bool originalFogEnabled;

		private FogMode originalFogMode;

		private Color originalFogColor;

		private float originalFogDensity;

		private Color originalAmbientLight;

		private Material? originalSkybox;

		private Material? domainSkyboxMaterial;

		private Material? selfEmbodimentHandMaterial;

		private Material? selfEmbodimentHandAccentMaterial;

		private Material? selfEmbodimentCrystalMaterial;

		private Transform? selfEmbodimentCrystalRoot;

		private float selfEmbodimentVisualTime;

		private bool skyboxCaptured;

		private Camera? domainGameplayCamera;

		private CameraClearFlags originalCameraClearFlags;

		private Color originalCameraBackgroundColor;

		private bool domainCameraCaptured;

		private bool domainArenaActivated;

		private bool localPlayerInDomainArena;

		private bool localPlayerReturnCaptured;

		private int arenaRoundInstanceId;

		private float idleDeathGambleVisualTime;

		private float idleDeathGambleRollPulse;

		private DomainKind selectedDomain;

		private bool menuOpen;

		private bool domainOpen;

		private bool openingActive;

		private bool domainVisualBuilt;

		private bool domainAffectsGameplay;

		private bool readyTipShown;

		private bool inputDebugLogged;

		private bool networkHandlersRegistered;

		private NetworkManager? registeredNetworkManager;

		private Harmony? harmony;

		private bool runtimeCallbacksRegistered;

		private bool runtimeDriverLogged;

		private bool runtimeShutdown;

		private bool pluginHostDestroyed;

		private bool detachedRuntimeTickLogged;

		private bool applicationQuitting;

		private bool runtimeResourcesInitialized;

		private bool runtimeInitializing;

		private bool domainSoundLoadScheduled;

		private bool jackpotSoundLoadScheduled;

		private bool selfEmbodimentOpeningWarningLogged;

		private bool domainRequestPending;

		private DomainKind pendingDomainRequest;

		private Vector3 pendingDomainCenter;

		private ulong pendingDomainCasterId;

		private float domainRequestRetryTimer;

		private int domainRequestAttempts;

		private bool moonUsageStateInitialized;

		private bool previousShipHasLanded;

		private bool domainUsesAvailableOnMoon;

		private bool hostConfigReceived;

		private int syncedDomainUsesPerMoon = 1;

		private bool syncedInfiniteDomainUses;

		private float configSyncTimer;

		private int moonUsageLevelId = int.MinValue;

		private int lastTickFrame = -1;

		private int lastLateTickFrame = -1;

		private int lastMenuToggleFrame = -1;

		private int lastDirectHotkeyFrame = -1;

		private float openingTime;

		private float domainTimeLeft;

		private float activeDomainDuration;

		private float openingEndRealtime;

		private float domainEndRealtime;

		private float effectTimer;

		private float gambleTimer;

		private float barrierTipCooldown;

		private float jackpotRegenTimeLeft;

		private float jackpotRegenTick;

		private float spinDisplayTimeLeft;

		private int jackpotRoll;

		private ulong casterClientId;

		private ulong activeDomainSessionId;

		private ulong nextHostDomainSessionId = 1uL;

		private Vector3 activeDomainArenaCenter;

		private ulong jackpotRegenClientId = ulong.MaxValue;

		private Vector3 domainCenter;

		private Vector3 domainSourceCenter;

		private Vector3 localPlayerReturnPosition;

		private Quaternion localPlayerReturnRotation;

		private Vector3 lastLocalPlayerPosition;

		private bool hasLastLocalPlayerPosition;

		private GameObject? driverHost;

		private DomainRuntimeDriver? runtimeDriver;

		private GameObject? menuCanvasRoot;

		private Text? menuText;

		private GameObject? spinCanvasRoot;

		private Text? spinText;

		private GameObject? soulHudCanvasRoot;

		private Image? soulHudFill;

		private Text? soulHudText;

		private GameObject? domainRoot;

		private GameObject? openingRoot;

		private GameObject? infiniteVoidOverlayRoot;

		private GameObject? jackpotSoundObject;

		private AudioSource? jackpotSoundSource;

		private Light? domainLight;

		private string statusText = "Press 0, F1, or Insert to open the menu.";

		private string soundDirectory = string.Empty;

		private string textureDirectory = string.Empty;

		private float infiniteVoidVisualTime;

		private float malevolentShrineVisualTime;

		internal static ManualLogSource Log { get; private set; }

		internal static Plugin? Instance { get; private set; }

		private void Awake()
		{
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin Awake: enabled=" + ((Behaviour)this).enabled + ", active=" + ((Component)this).gameObject.activeInHierarchy + ", host=" + ((Object)((Component)this).gameObject).name + "."));
			InitializeRuntimeHooks();
			BindConfig();
			InitializeInputActions();
			soundDirectory = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? Paths.PluginPath, "sounds");
			textureDirectory = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? Paths.PluginPath, "textures");
			Log.LogInfo((object)"Runtime scene objects are deferred until the first post-chainloader frame.");
			Log.LogInfo((object)"LethalCompanyMod 1.18.2 loaded. 0/F1/Insert menu, F2-F6 domains, multiplayer opening sync enabled.");
		}

		private void OnEnable()
		{
			if (Log != null)
			{
				Log.LogInfo((object)("Plugin OnEnable: active=" + ((Component)this).gameObject.activeInHierarchy + "."));
			}
		}

		private void Start()
		{
			Log.LogInfo((object)"Plugin Start callback fired.");
		}

		private void OnDisable()
		{
			if (Log != null)
			{
				Log.LogInfo((object)"Plugin OnDisable callback fired; persistent runtime driver remains active.");
			}
		}

		private void BindConfig()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			domainUsesPerMoonConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Domain Usage", "Domains Per Moon", 1, new ConfigDescription("How many Domain Expansions each player may use after the ship lands. The host's value controls multiplayer lobbies.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
			infiniteDomainUsesConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Domain Usage", "Infinite Domains (Debug)", false, "Allows unlimited Domain Expansions while the ship is landed. The host's value controls multiplayer lobbies.");
			domainUsesPerMoonConfig.SettingChanged += OnDomainConfigChanged;
			infiniteDomainUsesConfig.SettingChanged += OnDomainConfigChanged;
		}

		private void OnDomainConfigChanged(object sender, EventArgs args)
		{
			configSyncTimer = 0f;
			Log.LogInfo((object)("Domain usage config changed: uses=" + GetConfiguredDomainUsesPerMoon() + ", infinite=" + infiniteDomainUsesConfig.Value + "."));
		}

		private void OnDestroy()
		{
			if (!applicationQuitting && !runtimeShutdown)
			{
				pluginHostDestroyed = true;
				if (Log != null)
				{
					Log.LogInfo((object)"Plugin Unity host was destroyed after chainloading; static runtime hooks will bootstrap the post-boot driver.");
				}
			}
			else
			{
				ShutdownRuntime();
			}
		}

		internal void ShutdownRuntime()
		{
			if (runtimeShutdown)
			{
				return;
			}
			runtimeShutdown = true;
			if (Log != null)
			{
				Log.LogInfo((object)"Shutting down detached domain runtime.");
			}
			UnregisterNetworkHandlers();
			StopJackpotSound();
			CloseDomain(broadcast: false);
			ClearKnownDomainSessions();
			ClearPersistentDomainArenas();
			DisposeInputActions();
			UnregisterRuntimeCallbacks();
			if (harmony != null)
			{
				try
				{
					harmony.UnpatchSelf();
				}
				catch (Exception ex)
				{
					if (Log != null)
					{
						Log.LogDebug((object)("Runtime hooks were already removed: " + ex.Message));
					}
				}
				harmony = null;
			}
			if ((Object)(object)driverHost != (Object)null)
			{
				Object.Destroy((Object)(object)driverHost);
				driverHost = null;
			}
			runtimeDriver = null;
			Instance = null;
		}

		private void AttachDriver()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!IsRuntimeDriverAlive())
			{
				driverHost = new GameObject("LethalCompanyModDriverHost");
				Object.DontDestroyOnLoad((Object)(object)driverHost);
				runtimeDriver = driverHost.AddComponent<DomainRuntimeDriver>();
				runtimeDriver.Initialize(this);
				Log.LogInfo((object)("Top-level runtime driver attached: enabled=" + ((Behaviour)runtimeDriver).enabled + ", active=" + driverHost.activeInHierarchy + "."));
			}
		}

		private bool IsRuntimeDriverAlive()
		{
			if (driverHost != null && (Object)(object)driverHost != (Object)null && runtimeDriver != null)
			{
				return (Object)(object)runtimeDriver != (Object)null;
			}
			return false;
		}

		private bool EnsureRuntimeInitialized()
		{
			if (runtimeShutdown || applicationQuitting)
			{
				return false;
			}
			if (runtimeResourcesInitialized && IsRuntimeDriverAlive())
			{
				return true;
			}
			if (runtimeInitializing)
			{
				return false;
			}
			runtimeInitializing = true;
			try
			{
				if (!runtimeResourcesInitialized)
				{
					CreateCanvasMenu();
					CreateSpinDisplay();
					LoadVisualTextures();
					if ((Object)(object)slotRollClip == (Object)null)
					{
						slotRollClip = CreateSlotRollClip();
					}
					runtimeResourcesInitialized = true;
				}
				if (!IsRuntimeDriverAlive())
				{
					AttachDriver();
				}
				int length = Enum.GetValues(typeof(DomainKind)).Length;
				if ((domainSounds.Count < length || (Object)(object)selfEmbodimentOpeningClip == (Object)null) && !domainSoundLoadScheduled)
				{
					domainSoundLoadScheduled = StartRuntimeCoroutine(LoadDomainSoundsTracked());
				}
				if ((Object)(object)jackpotSoundClip == (Object)null && !jackpotSoundLoadScheduled)
				{
					jackpotSoundLoadScheduled = StartRuntimeCoroutine(LoadJackpotSoundTracked());
				}
				Log.LogInfo((object)"Post-chainloader runtime scene objects initialized.");
				return IsRuntimeDriverAlive();
			}
			catch (Exception ex)
			{
				runtimeResourcesInitialized = false;
				Log.LogError((object)("Could not initialize the post-chainloader runtime: " + ex));
				return false;
			}
			finally
			{
				runtimeInitializing = false;
			}
		}

		private bool StartRuntimeCoroutine(IEnumerator routine)
		{
			if (!IsRuntimeDriverAlive() && !runtimeInitializing)
			{
				EnsureRuntimeInitialized();
			}
			DomainRuntimeDriver domainRuntimeDriver = runtimeDriver;
			if (domainRuntimeDriver != null && (Object)(object)domainRuntimeDriver != (Object)null)
			{
				domainRuntimeDriver.StartManagedCoroutine(routine);
				return true;
			}
			Log.LogWarning((object)"Could not start a runtime coroutine because no live post-boot driver exists.");
			return false;
		}

		internal void NotifyRuntimeDriverDestroyed(DomainRuntimeDriver driver)
		{
			if (runtimeDriver == driver)
			{
				runtimeDriver = null;
				driverHost = null;
				if (!applicationQuitting && !runtimeShutdown)
				{
					domainSoundLoadScheduled = false;
					jackpotSoundLoadScheduled = false;
					Log.LogInfo((object)"Runtime driver was removed during scene cleanup and will be recreated on the next game frame.");
				}
			}
		}

		internal void NotifyApplicationQuitting()
		{
			applicationQuitting = true;
			ShutdownRuntime();
		}

		private void InitializeRuntimeHooks()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			RegisterRuntimeCallbacks();
			try
			{
				harmony = new Harmony("anton.lethalcompanymod");
				int num = 0;
				num += PatchRuntimeMethod(typeof(StartOfRound), "Update", "HarmonyTickPostfix");
				num += PatchRuntimeMethod(typeof(PlayerControllerB), "Update", "HarmonyTickPostfix");
				num += PatchRuntimeMethod(typeof(HUDManager), "Update", "HarmonyTickPostfix");
				num += PatchRuntimeMethod(typeof(StartOfRound), "LateUpdate", "HarmonyLateTickPostfix");
				num += PatchRuntimeMethod(typeof(PlayerControllerB), "LateUpdate", "HarmonyLateTickPostfix");
				Log.LogInfo((object)("Installed " + num + "/5 explicit game update hooks for the domain runtime driver."));
			}
			catch (Exception ex)
			{
				harmony = null;
				Log.LogWarning((object)("Could not install explicit game runtime hooks; render and Unity drivers remain active: " + ex));
			}
		}

		private int PatchRuntimeMethod(Type targetType, string targetMethodName, string postfixMethodName)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			if (harmony == null)
			{
				return 0;
			}
			MethodInfo methodInfo = AccessTools.Method(targetType, targetMethodName, (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), postfixMethodName, (Type[])null, (Type[])null);
			if (methodInfo == null || methodInfo2 == null)
			{
				Log.LogWarning((object)("Runtime hook target was not found: " + targetType.FullName + "." + targetMethodName + "."));
				return 0;
			}
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			return 1;
		}

		private void RegisterRuntimeCallbacks()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			if (!runtimeCallbacksRegistered)
			{
				Application.onBeforeRender += new UnityAction(OnBeforeRenderRuntimeTick);
				Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(OnCameraPreCullRuntimeTick));
				Application.quitting += NotifyApplicationQuitting;
				runtimeCallbacksRegistered = true;
				Log.LogInfo((object)"Registered render and camera runtime callbacks.");
			}
		}

		private void UnregisterRuntimeCallbacks()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			if (runtimeCallbacksRegistered)
			{
				Application.onBeforeRender -= new UnityAction(OnBeforeRenderRuntimeTick);
				Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(OnCameraPreCullRuntimeTick));
				Application.quitting -= NotifyApplicationQuitting;
				runtimeCallbacksRegistered = false;
			}
		}

		private void OnBeforeRenderRuntimeTick()
		{
			LogRuntimeDriverOnce("Application.onBeforeRender");
			Tick();
			LateTick();
		}

		private void OnCameraPreCullRuntimeTick(Camera camera)
		{
			LogRuntimeDriverOnce("Camera.onPreCull");
			Tick();
			LateTick();
		}

		internal void LogRuntimeDriverOnce(string driver)
		{
			if (!runtimeDriverLogged)
			{
				runtimeDriverLogged = true;
				Log.LogInfo((object)("Domain runtime driver is active through " + driver + "."));
			}
		}

		private static void HarmonyTickPostfix()
		{
			Plugin instance = Instance;
			if (instance != null)
			{
				instance.LogRuntimeDriverOnce("explicit Harmony Update postfix");
				instance.Tick();
			}
		}

		private static void HarmonyLateTickPostfix()
		{
			Plugin instance = Instance;
			if (instance != null)
			{
				instance.LogRuntimeDriverOnce("explicit Harmony LateUpdate postfix");
				instance.LateTick();
			}
		}

		public void Update()
		{
			Tick();
		}

		public void LateUpdate()
		{
			LateTick();
		}

		internal void LateTick()
		{
			if (lastLateTickFrame == Time.frameCount)
			{
				return;
			}
			lastLateTickFrame = Time.frameCount;
			if (domainOpen && !openingActive && domainVisualBuilt)
			{
				MaintainRemoteDomainPlayerRepresentations();
				if (!HasClosedBarrier() || localPlayerInDomainArena)
				{
					EnforceDomainAtmosphere();
				}
			}
		}

		internal void Tick()
		{
			if (runtimeShutdown || applicationQuitting || lastTickFrame == Time.frameCount)
			{
				return;
			}
			lastTickFrame = Time.frameCount;
			if ((pluginHostDestroyed || Time.frameCount >= 5) && !EnsureRuntimeInitialized())
			{
				return;
			}
			if (pluginHostDestroyed && !detachedRuntimeTickLogged)
			{
				detachedRuntimeTickLogged = true;
				Log.LogInfo((object)"Detached runtime confirmed active after BepInEx Manager teardown.");
			}
			LogInputDebugOnce();
			HandleMenuKeyboard();
			HandleDirectDomainHotkeys();
			HandleMenuToggle();
			TryRegisterNetworkHandlers();
			UpdatePendingDomainRequest();
			UpdateConfigSynchronization();
			UpdateHostDomainSessions();
			CloseUnnetworkedDomainIfCasterDied();
			EnsurePersistentDomainArenas();
			UpdateDomainUsageMoonState();
			ShowReadyTipOnce();
			UpdateCanvasMenu();
			UpdateSpinDisplay();
			UpdateSoulMeterVisuals();
			ApplyJackpotRegeneration();
			if (domainOpen)
			{
				UpdateOpeningAndDomainVisuals();
				ApplyInfiniteVoidPlayerSlow();
				ApplyClosedBarrierContainment();
				domainTimeLeft = domainEndRealtime - Time.realtimeSinceStartup;
				effectTimer -= Time.unscaledDeltaTime;
				if (!openingActive && effectTimer <= 0f)
				{
					effectTimer = 0.35f;
					ApplyDomainEffect();
				}
				if (domainTimeLeft <= -2f && !IsHostManagingActiveDomain())
				{
					CloseDomain(broadcast: false);
				}
			}
		}

		private void HandleMenuToggle()
		{
			Keyboard current = Keyboard.current;
			bool fallbackHeld = IsHeld((current != null) ? current.digit0Key : null, (KeyCode)48) || IsHeld((current != null) ? current.numpad0Key : null, (KeyCode)256) || IsHeld((current != null) ? current.f1Key : null, (KeyCode)282) || IsHeld((current != null) ? current.insertKey : null, (KeyCode)277);
			if (ConsumeCommandPress(DomainInputCommand.ToggleMenu, fallbackHeld) && lastMenuToggleFrame != Time.frameCount)
			{
				lastMenuToggleFrame = Time.frameCount;
				menuOpen = !menuOpen;
				statusText = (menuOpen ? "Domain menu opened." : "Domain menu closed.");
				Log.LogInfo((object)statusText);
			}
		}

		private void CreateCanvasMenu()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)menuCanvasRoot != (Object)null))
			{
				menuCanvasRoot = new GameObject("DomainMenuCanvas");
				Object.DontDestroyOnLoad((Object)(object)menuCanvasRoot);
				Canvas obj = menuCanvasRoot.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 32767;
				CanvasScaler obj2 = menuCanvasRoot.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				obj2.matchWidthOrHeight = 0.5f;
				menuCanvasRoot.AddComponent<GraphicRaycaster>();
				GameObject val = new GameObject("Panel");
				val.transform.SetParent(menuCanvasRoot.transform, false);
				((Graphic)val.AddComponent<Image>()).color = new Color(0f, 0f, 0f, 0.74f);
				RectTransform component = val.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.03f, 0.12f);
				component.anchorMax = new Vector2(0.38f, 0.58f);
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				GameObject val2 = new GameObject("MenuText");
				val2.transform.SetParent(val.transform, false);
				menuText = val2.AddComponent<Text>();
				menuText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				menuText.fontSize = 18;
				((Graphic)menuText).color = new Color(0.78f, 1f, 1f, 1f);
				menuText.alignment = (TextAnchor)0;
				menuText.horizontalOverflow = (HorizontalWrapMode)0;
				menuText.verticalOverflow = (VerticalWrapMode)1;
				RectTransform component2 = val2.GetComponent<RectTransform>();
				component2.anchorMin = Vector2.zero;
				component2.anchorMax = Vector2.one;
				component2.offsetMin = new Vector2(16f, 12f);
				component2.offsetMax = new Vector2(-16f, -12f);
				menuCanvasRoot.SetActive(false);
			}
		}

		private void CreateSpinDisplay()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_013e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)spinCanvasRoot != (Object)null))
			{
				spinCanvasRoot = new GameObject("IdleDeathGambleSpinCanvas");
				Object.DontDestroyOnLoad((Object)(object)spinCanvasRoot);
				Canvas obj = spinCanvasRoot.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 32766;
				CanvasScaler obj2 = spinCanvasRoot.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				obj2.matchWidthOrHeight = 0.5f;
				GameObject val = new GameObject("SpinText");
				val.transform.SetParent(spinCanvasRoot.transform, false);
				spinText = val.AddComponent<Text>();
				spinText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				spinText.fontSize = 52;
				spinText.fontStyle = (FontStyle)1;
				spinText.supportRichText = true;
				spinText.alignment = (TextAnchor)4;
				spinText.horizontalOverflow = (HorizontalWrapMode)1;
				spinText.verticalOverflow = (VerticalWrapMode)1;
				RectTransform component = val.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.34f, 0.67f);
				component.anchorMax = new Vector2(0.66f, 0.84f);
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				spinCanvasRoot.SetActive(false);
			}
		}

		private void UpdateSpinDisplay()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)spinCanvasRoot == (Object)null)
			{
				CreateSpinDisplay();
			}
			if ((Object)(object)spinCanvasRoot == (Object)null)
			{
				return;
			}
			if (spinDisplayTimeLeft > 0f)
			{
				spinDisplayTimeLeft -= Time.unscaledDeltaTime;
				if (!spinCanvasRoot.activeSelf)
				{
					spinCanvasRoot.SetActive(true);
				}
				if ((Object)(object)spinText != (Object)null)
				{
					Color color = ((Graphic)spinText).color;
					color.a = Mathf.Clamp01(spinDisplayTimeLeft / 0.55f);
					((Graphic)spinText).color = color;
				}
			}
			else if (spinCanvasRoot.activeSelf)
			{
				spinCanvasRoot.SetActive(false);
			}
		}

		private void ShowGambleRoll(int roll, bool jackpot)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)spinText == (Object)null)
			{
				CreateSpinDisplay();
			}
			if (!((Object)(object)spinText == (Object)null))
			{
				spinText.text = (jackpot ? ("<color=#FFD633>JACKPOT</color>\n<color=#000000>" + roll + "</color>") : ("<color=#000000>ROLL\n" + roll + "</color>"));
				((Graphic)spinText).color = Color.white;
				spinDisplayTimeLeft = (jackpot ? 3.2f : 2.1f);
				if ((Object)(object)spinCanvasRoot != (Object)null)
				{
					spinCanvasRoot.SetActive(true);
				}
			}
		}

		private void CreateSoulHud()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Expected O, but got Unknown
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)soulHudCanvasRoot != (Object)null))
			{
				soulHudCanvasRoot = new GameObject("SelfEmbodimentSoulHud");
				Object.DontDestroyOnLoad((Object)(object)soulHudCanvasRoot);
				Canvas obj = soulHudCanvasRoot.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 32765;
				CanvasScaler obj2 = soulHudCanvasRoot.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				obj2.matchWidthOrHeight = 0.5f;
				((Graphic)CreateSoulImage("Soul HUD Glow", soulHudCanvasRoot.transform, new Color(0.82f, 0.12f, 1f, 0.24f), new Vector2(0.027f, 0.29f), new Vector2(0.066f, 0.69f))).raycastTarget = false;
				((Graphic)CreateSoulImage("Soul HUD Frame", soulHudCanvasRoot.transform, new Color(0.92f, 0.36f, 1f, 1f), new Vector2(0.033f, 0.31f), new Vector2(0.06f, 0.67f))).raycastTarget = false;
				((Graphic)CreateSoulImage("Soul HUD Backing", soulHudCanvasRoot.transform, new Color(0.045f, 0.008f, 0.06f, 0.96f), new Vector2(0.037f, 0.318f), new Vector2(0.056f, 0.662f))).raycastTarget = false;
				soulHudFill = CreateSoulImage("Soul HUD Fill", soulHudCanvasRoot.transform, Color.white, new Vector2(0.039f, 0.322f), new Vector2(0.054f, 0.658f));
				soulHudFill.type = (Type)0;
				((Graphic)soulHudFill).rectTransform.pivot = new Vector2(0.5f, 0f);
				((Graphic)soulHudFill).raycastTarget = false;
				GameObject val = new GameObject("Soul HUD Text");
				val.transform.SetParent(soulHudCanvasRoot.transform, false);
				soulHudText = val.AddComponent<Text>();
				soulHudText.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				soulHudText.fontSize = 23;
				soulHudText.fontStyle = (FontStyle)1;
				soulHudText.alignment = (TextAnchor)3;
				((Graphic)soulHudText).color = new Color(0.96f, 0.82f, 1f, 1f);
				RectTransform component = val.GetComponent<RectTransform>();
				component.anchorMin = new Vector2(0.066f, 0.43f);
				component.anchorMax = new Vector2(0.18f, 0.57f);
				component.offsetMin = Vector2.zero;
				component.offsetMax = Vector2.zero;
				soulHudCanvasRoot.SetActive(false);
			}
		}

		private static Image CreateSoulImage(string name, Transform parent, Color color, Vector2 anchorMin, Vector2 anchorMax)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			Image val2 = val.AddComponent<Image>();
			((Graphic)val2).color = color;
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = anchorMin;
			component.anchorMax = anchorMax;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			return val2;
		}

		private void UpdateSoulMeterVisuals()
		{
			if (!domainOpen || openingActive || !localPlayerInDomainArena || selectedDomain != DomainKind.SelfEmbodimentOfPerfection)
			{
				if ((Object)(object)soulHudCanvasRoot != (Object)null && soulHudCanvasRoot.activeSelf)
				{
					soulHudCanvasRoot.SetActive(false);
				}
				return;
			}
			Camera val = StartOfRound.Instance?.localPlayerController?.gameplayCamera ?? Camera.main;
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			ulong localClientId = GetLocalClientId();
			HashSet<ulong> hashSet = new HashSet<ulong>();
			foreach (KeyValuePair<ulong, float> localPlayerSoulValue in localPlayerSoulValues)
			{
				if (localPlayerSoulValue.Key != localClientId)
				{
					PlayerControllerB val2 = FindPlayerByActualClientId(localPlayerSoulValue.Key);
					if (!((Object)(object)val2 == (Object)null) && !IsPlayerDead(val2))
					{
						hashSet.Add(localPlayerSoulValue.Key);
						UpdateSoulMeter(playerSoulMeters, localPlayerSoulValue.Key, ((Component)val2).transform, localPlayerSoulValue.Value, val);
					}
				}
			}
			PruneSoulMeters(playerSoulMeters, hashSet);
			HashSet<ulong> hashSet2 = new HashSet<ulong>();
			foreach (KeyValuePair<EnemyAI, float> localDirectEnemySoulValue in localDirectEnemySoulValues)
			{
				if (!((Object)(object)localDirectEnemySoulValue.Key == (Object)null) && !IsEnemyDead(localDirectEnemySoulValue.Key))
				{
					ulong localEnemyVisualId = GetLocalEnemyVisualId(localDirectEnemySoulValue.Key);
					hashSet2.Add(localEnemyVisualId);
					UpdateSoulMeter(enemySoulMeters, localEnemyVisualId, ((Component)localDirectEnemySoulValue.Key).transform, localDirectEnemySoulValue.Value, val);
				}
			}
			foreach (KeyValuePair<ulong, float> localEnemySoulValue in localEnemySoulValues)
			{
				if (hashSet2.Contains(localEnemySoulValue.Key))
				{
					continue;
				}
				Transform val3 = FindEnemyTransformByNetworkId(localEnemySoulValue.Key);
				if (!((Object)(object)val3 == (Object)null))
				{
					EnemyAI val4 = ((Component)val3).GetComponent<EnemyAI>() ?? ((Component)val3).GetComponentInChildren<EnemyAI>();
					if (!((Object)(object)val4 != (Object)null) || !IsEnemyDead(val4))
					{
						hashSet2.Add(localEnemySoulValue.Key);
						UpdateSoulMeter(enemySoulMeters, localEnemySoulValue.Key, val3, localEnemySoulValue.Value, val);
					}
				}
			}
			PruneSoulMeters(enemySoulMeters, hashSet2);
			if (localPlayerSoulValues.TryGetValue(localClientId, out var value))
			{
				if ((Object)(object)soulHudCanvasRoot == (Object)null)
				{
					CreateSoulHud();
				}
				if ((Object)(object)soulHudCanvasRoot != (Object)null && !soulHudCanvasRoot.activeSelf)
				{
					soulHudCanvasRoot.SetActive(true);
				}
				SetSoulFill(soulHudFill, value);
				if ((Object)(object)soulHudText != (Object)null)
				{
					soulHudText.text = "SOUL  " + Mathf.CeilToInt(value);
				}
			}
			else if ((Object)(object)soulHudCanvasRoot != (Object)null && soulHudCanvasRoot.activeSelf)
			{
				soulHudCanvasRoot.SetActive(false);
			}
		}

		private void UpdateSoulMeter(Dictionary<ulong, SoulMeterVisual> meters, ulong id, Transform target, float soul, Camera camera)
		{
			//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_0050: 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_0061: 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_0070: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			if (!meters.TryGetValue(id, out SoulMeterVisual value) || (Object)(object)value.Root == (Object)null)
			{
				value = (meters[id] = CreateWorldSoulMeter(target, camera));
			}
			value.Target = target;
			float soulMeterTargetHeight = GetSoulMeterTargetHeight(target);
			value.Root.transform.position = target.position + Vector3.up * soulMeterTargetHeight + ((Component)camera).transform.right * 0.72f;
			value.Root.transform.rotation = Quaternion.LookRotation(value.Root.transform.position - ((Component)camera).transform.position, ((Component)camera).transform.up);
			float num = ((soul <= 20f) ? (1f + Mathf.Sin(Time.unscaledTime * 11f) * 0.08f) : 1f);
			value.Root.transform.localScale = Vector3.one * (0.0065f * num);
			SetSoulFill(value.Fill, soul);
		}

		private SoulMeterVisual CreateWorldSoulMeter(Transform target, Camera camera)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Soul Meter - " + ((Object)target).name);
			if ((Object)(object)domainRoot != (Object)null)
			{
				val.transform.SetParent(domainRoot.transform, false);
			}
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)2;
			obj.worldCamera = camera;
			obj.overrideSorting = true;
			obj.sortingOrder = 32000;
			val.GetComponent<RectTransform>().sizeDelta = new Vector2(42f, 172f);
			((Graphic)CreateSoulImage("Soul Meter Glow", val.transform, new Color(0.76f, 0.08f, 1f, 0.28f), new Vector2(-0.12f, -0.04f), new Vector2(1.12f, 1.04f))).raycastTarget = false;
			((Graphic)CreateSoulImage("Soul Meter Frame", val.transform, new Color(0.96f, 0.38f, 1f, 1f), Vector2.zero, Vector2.one)).raycastTarget = false;
			((Graphic)CreateSoulImage("Soul Meter Backing", val.transform, new Color(0.035f, 0.004f, 0.05f, 0.98f), new Vector2(0.16f, 0.035f), new Vector2(0.84f, 0.965f))).raycastTarget = false;
			Image val2 = CreateSoulImage("Soul Meter Fill", val.transform, Color.white, new Vector2(0.22f, 0.065f), new Vector2(0.78f, 0.935f));
			val2.type = (Type)0;
			((Graphic)val2).rectTransform.pivot = new Vector2(0.5f, 0f);
			((Graphic)val2).raycastTarget = false;
			val.transform.localScale = Vector3.one * 0.0065f;
			return new SoulMeterVisual
			{
				Root = val,
				Fill = val2,
				Target = target
			};
		}

		private static float GetSoulMeterTargetHeight(Transform target)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			float num = target.position.y + 1.8f;
			Renderer[] componentsInChildren = ((Component)target).GetComponentsInChildren<Renderer>();
			foreach (Renderer val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					float num2 = num;
					Bounds bounds = val.bounds;
					num = Mathf.Max(num2, ((Bounds)(ref bounds)).max.y);
				}
			}
			return Mathf.Clamp(num - target.position.y + 0.35f, 1.7f, 4.8f);
		}

		private static void SetSoulFill(Image? fill, float soul)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)fill == (Object)null))
			{
				float num = Mathf.Clamp01(soul / 100f);
				fill.fillAmount = 1f;
				((Transform)((Graphic)fill).rectTransform).localScale = new Vector3(1f, num, 1f);
				((Graphic)fill).color = (Color)((soul <= 20f) ? new Color(1f, 0.08f, 0.16f, 1f) : ((soul <= 50f) ? new Color(1f, 0.2f, 0.78f, 1f) : Color.white));
			}
		}

		private static Transform? FindEnemyTransformByNetworkId(ulong networkObjectId)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.SpawnManager == null || !singleton.SpawnManager.SpawnedObjects.TryGetValue(networkObjectId, out var value) || (Object)(object)value == (Object)null)
			{
				return null;
			}
			EnemyAI val = ((Component)value).GetComponent<EnemyAI>() ?? ((Component)value).GetComponentInChildren<EnemyAI>();
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return ((Component)val).transform;
		}

		private static void PruneSoulMeters(Dictionary<ulong, SoulMeterVisual> meters, HashSet<ulong> visibleIds)
		{
			foreach (ulong item in new List<ulong>(meters.Keys))
			{
				SoulMeterVisual soulMeterVisual = meters[item];
				if (!visibleIds.Contains(item) || !((Object)(object)soulMeterVisual.Root != (Object)null) || !((Object)(object)soulMeterVisual.Target != (Object)null))
				{
					if ((Object)(object)soulMeterVisual.Root != (Object)null)
					{
						Object.Destroy((Object)(object)soulMeterVisual.Root);
					}
					meters.Remove(item);
				}
			}
		}

		private void ClearSoulMeterVisuals()
		{
			foreach (SoulMeterVisual value in playerSoulMeters.Values)
			{
				if ((Object)(object)value.Root != (Object)null)
				{
					Object.Destroy((Object)(object)value.Root);
				}
			}
			foreach (SoulMeterVisual value2 in enemySoulMeters.Values)
			{
				if ((Object)(object)value2.Root != (Object)null)
				{
					Object.Destroy((Object)(object)value2.Root);
				}
			}
			playerSoulMeters.Clear();
			enemySoulMeters.Clear();
			localPlayerSoulValues.Clear();
			localEnemySoulValues.Clear();
			localDirectEnemySoulValues.Clear();
			if ((Object)(object)soulHudCanvasRoot != (Object)null)
			{
				soulHudCanvasRoot.SetActive(false);
			}
		}

		private void UpdateCanvasMenu()
		{
			if ((Object)(object)menuCanvasRoot == (Object)null)
			{
				CreateCanvasMenu();
			}
			if ((Object)(object)menuCanvasRoot != (Object)null && menuCanvasRoot.activeSelf != menuOpen)
			{
				menuCanvasRoot.SetActive(menuOpen);
			}
			if (!((Object)(object)menuText == (Object)null))
			{
				menuText.text = "DOMAIN EXPANSION MENU\n\n1 - Infinite Void" + SelectedMark(DomainKind.InfiniteVoid) + "\n2 - Malevolent Shrine Open" + SelectedMark(DomainKind.MalevolentShrineOpen) + "\n3 - Malevolent Shrine Closed" + SelectedMark(DomainKind.MalevolentShrineClosed) + "\n4 - Idle Death Gamble" + SelectedMark(DomainKind.IdleDeathGamble) + "\n5 - Self-Embodiment of Perfection" + SelectedMark(DomainKind.SelfEmbodimentOfPerfection) + "\n\nDomain uses: " + GetLocalDomainUsesDisplay() + "\nEnter - Open selected domain\nF2/F3/F4/F5/F6 - Direct domains\n0 / F1 / Insert - Toggle menu\n\n" + statusText;
			}
		}

		private string SelectedMark(DomainKind domain)
		{
			if (selectedDomain != domain)
			{
				return string.Empty;
			}
			return "  <";
		}

		private string GetLocalDomainUsesDisplay()
		{
			if (!domainUsesAvailableOnMoon)
			{
				return "0";
			}
			if (InfiniteDomainUsesEnabled())
			{
				return "Infinite";
			}
			int effectiveDomainUsesPerMoon = GetEffectiveDomainUsesPerMoon();
			int consumedDomainUses = GetConsumedDomainUses(GetLocalClientId());
			return Mathf.Max(0, effectiveDomainUsesPerMoon - consumedDomainUses) + " / " + effectiveDomainUsesPerMoon;
		}

		private void HandleMenuKeyboard()
		{
			Keyboard current = Keyboard.current;
			if (menuOpen)
			{
				if (ConsumeCommandPress(DomainInputCommand.Select1, IsHeld((current != null) ? current.digit1Key : null, (KeyCode)49) || IsHeld((current != null) ? current.numpad1Key : null, (KeyCode)257)))
				{
					selectedDomain = DomainKind.InfiniteVoid;
				}
				if (ConsumeCommandPress(DomainInputCommand.Select2, IsHeld((current != null) ? current.digit2Key : null, (KeyCode)50) || IsHeld((current != null) ? current.numpad2Key : null, (KeyCode)258)))
				{
					selectedDomain = DomainKind.MalevolentShrineOpen;
				}
				if (ConsumeCommandPress(DomainInputCommand.Select3, IsHeld((current != null) ? current.digit3Key : null, (KeyCode)51) || IsHeld((current != null) ? current.numpad3Key : null, (KeyCode)259)))
				{
					selectedDomain = DomainKind.MalevolentShrineClosed;
				}
				if (ConsumeCommandPress(DomainInputCommand.Select4, IsHeld((current != null) ? current.digit4Key : null, (KeyCode)52) || IsHeld((current != null) ? current.numpad4Key : null, (KeyCode)260)))
				{
					selectedDomain = DomainKind.IdleDeathGamble;
				}
				if (ConsumeCommandPress(DomainInputCommand.Select5, IsHeld((current != null) ? current.digit5Key : null, (KeyCode)53) || IsHeld((current != null) ? current.numpad5Key : null, (KeyCode)261)))
				{
					selectedDomain = DomainKind.SelfEmbodimentOfPerfection;
				}
				if (ConsumeCommandPress(DomainInputCommand.Confirm, IsHeld((current != null) ? current.enterKey : null, (KeyCode)13) || IsHeld((current != null) ? current.numpadEnterKey : null, (KeyCode)271)))
				{
					menuOpen = false;
					OpenSelectedDomain();
				}
			}
		}

		private void HandleDirectDomainHotkeys()
		{
			Keyboard current = Keyboard.current;
			if (lastDirectHotkeyFrame != Time.frameCount)
			{
				if (ConsumeCommandPress(DomainInputCommand.Direct1, IsHeld((current != null) ? current.f2Key : null, (KeyCode)283)))
				{
					OpenDomainDirect(DomainKind.InfiniteVoid);
				}
				else if (ConsumeCommandPress(DomainInputCommand.Direct2, IsHeld((current != null) ? current.f3Key : null, (KeyCode)284)))
				{
					OpenDomainDirect(DomainKind.MalevolentShrineOpen);
				}
				else if (ConsumeCommandPress(DomainInputCommand.Direct3, IsHeld((current != null) ? current.f4Key : null, (KeyCode)285)))
				{
					OpenDomainDirect(DomainKind.MalevolentShrineClosed);
				}
				else if (ConsumeCommandPress(DomainInputCommand.Direct4, IsHeld((current != null) ? current.f5Key : null, (KeyCode)286)))
				{
					OpenDomainDirect(DomainKind.IdleDeathGamble);
				}
				else if (ConsumeCommandPress(DomainInputCommand.Direct5, IsHeld((current != null) ? current.f6Key : null, (KeyCode)287)))
				{
					OpenDomainDirect(DomainKind.SelfEmbodimentOfPerfection);
				}
			}
		}

		private void OpenDomainDirect(DomainKind domain)
		{
			lastDirectHotkeyFrame = Time.frameCount;
			selectedDomain = domain;
			menuOpen = false;
			OpenSelectedDomain();
		}

		private void OpenSelectedDomain()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null)
			{
				statusText = "No local player found yet.";
				Log.LogWarning((object)statusText);
				return;
			}
			Vector3 position = ((Component)val).transform.position;
			ulong localClientId = GetLocalClientId();
			NetworkManager singleton = NetworkManager.Singleton;
			if (domainOpen)
			{
				ShowDomainBusy();
			}
			else if ((Object)(object)singleton != (Object)null && singleton.IsListening && !singleton.IsServer)
			{
				BeginDomainRequest(selectedDomain, position, localClientId);
				statusText = "Domain request sent to host: " + GetDomainName(selectedDomain) + ".";
				ShowTip("Domain requested", GetDomainName(selectedDomain));
			}
			else if ((Object)(object)singleton != (Object)null && singleton.IsListening && singleton.IsServer && IsClientInsideActiveHostDomain(localClientId))
			{
				ShowDomainBusy();
			}
			else if (!domainUsesAvailableOnMoon)
			{
				ShowDomainUnavailableInShip();
			}
			else if (!HasDomainUseRemaining(localClientId))
			{
				ShowDomainUsageDenied();
			}
			else if (TryConsumeDomainUse(localClientId))
			{
				float duration = RollDomainDuration(selectedDomain);
				Dictionary<int, Vector3> participants = CaptureDomainParticipants(selectedDomain, position, localClientId);
				if ((Object)(object)singleton != (Object)null && singleton.IsListening && singleton.IsServer)
				{
					StartHostDomainSession(selectedDomain, position, localClientId, duration, participants);
				}
				else
				{
					OpenDomainLocal(selectedDomain, position, localClientId, affectsGameplay: true, duration, participants, 0uL);
				}
			}
		}

		private void UpdateDomainUsageMoonState()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				moonUsageStateInitialized = false;
				previousShipHasLanded = false;
				domainUsesAvailableOnMoon = false;
				moonUsageLevelId = int.MinValue;
				domainUsesConsumedThisMoon.Clear();
				return;
			}
			object memberValue = GetMemberValue(instance, "shipHasLanded");
			bool flag = default(bool);
			int num;
			if (memberValue is bool)
			{
				flag = (bool)memberValue;
				num = 1;
			}
			else
			{
				num = 0;
			}
			bool flag2 = (byte)((uint)num & (flag ? 1u : 0u)) != 0;
			memberValue = GetMemberValue(instance, "inShipPhase");
			bool flag3 = default(bool);
			int num2;
			if (memberValue is bool)
			{
				flag3 = (bool)memberValue;
				num2 = 1;
			}
			else
			{
				num2 = 0;
			}
			bool flag4 = (byte)((uint)num2 & (flag3 ? 1u : 0u)) != 0;
			bool flag5 = flag2 && !flag4;
			int currentMoonLevelId = GetCurrentMoonLevelId(instance);
			if (!moonUsageStateInitialized)
			{
				moonUsageStateInitialized = true;
				previousShipHasLanded = flag5;
				domainUsesAvailableOnMoon = flag5;
				moonUsageLevelId = currentMoonLevelId;
				domainUsesConsumedThisMoon.Clear();
				Log.LogInfo((object)("Domain usage initialized for moon level " + currentMoonLevelId + "."));
				return;
			}
			if (flag5 && (!previousShipHasLanded || currentMoonLevelId != moonUsageLevelId))
			{
				domainUsesConsumedThisMoon.Clear();
				domainUsesAvailableOnMoon = true;
				Log.LogInfo((object)("Every player received " + (InfiniteDomainUsesEnabled() ? "unlimited" : GetEffectiveDomainUsesPerMoon().ToString()) + " domain use(s) for moon level " + currentMoonLevelId + "."));
			}
			else if (!flag5 && previousShipHasLanded)
			{
				domainUsesConsumedThisMoon.Clear();
				domainUsesAvailableOnMoon = false;
				Log.LogInfo((object)"Ship returned to orbit; every player's domain uses were set to zero.");
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.IsListening && singleton.IsServer)
				{
					CloseAllHostDomainSessions(broadcast: true);
				}
				else
				{
					if (domainOpen)
					{
						CloseDomain(broadcast: false);
					}
					ClearKnownDomainSessions();
				}
			}
			previousShipHasLanded = flag5;
			moonUsageLevelId = currentMoonLevelId;
		}

		private static int GetCurrentMoonLevelId(StartOfRound round)
		{
			object memberValue = GetMemberValue(round, "currentLevelID");
			if (memberValue is int)
			{
				return (int)memberValue;
			}
			object memberValue2 = GetMemberValue(round, "currentLevel");
			if (memberValue2 != null)
			{
				object memberValue3 = GetMemberValue(memberValue2, "levelID");
				if (memberValue3 is int)
				{
					return (int)memberValue3;
				}
			}
			return -1;
		}

		private bool TryConsumeDomainUse(ulong clientId)
		{
			if (!domainUsesAvailableOnMoon)
			{
				if (clientId == GetLocalClientId())
				{
					ShowDomainUnavailableInShip();
				}
				return false;
			}
			if (InfiniteDomainUsesEnabled())
			{
				Log.LogInfo((object)("Infinite debug domain use granted to client " + clientId + " on moon level " + moonUsageLevelId + "."));
				return true;
			}
			int consumedDomainUses = GetConsumedDomainUses(clientId);
			int effectiveDomainUsesPerMoon = GetEffectiveDomainUsesPerMoon();
			if (consumedDomainUses < effectiveDomainUsesPerMoon)
			{
				domainUsesConsumedThisMoon[clientId] = consumedDomainUses + 1;
				Log.LogInfo((object)("Domain use " + (consumedDomainUses + 1) + "/" + effectiveDomainUsesPerMoon + " consumed for client " + clientId + " on moon level " + moonUsageLevelId + "."));
				return true;
			}
			if (clientId == GetLocalClientId())
			{
				ShowDomainUsageDenied();
			}
			return false;
		}

		private bool HasDomainUseRemaining(ulong clientId)
		{
			if (domainUsesAvailableOnMoon)
			{
				if (!InfiniteDomainUsesEnabled())
				{
					return GetConsumedDomainUses(clientId) < GetEffectiveDomainUsesPerMoon();
				}
				return true;
			}
			return false;
		}

		private int GetConsumedDomainUses(ulong clientId)
		{
			if (!domainUsesConsumedThisMoon.TryGetValue(clientId, out var value))
			{
				return 0;
			}
			return value;
		}

		private void RecordConsumedDomainUse(ulong clientId)
		{
			if (!InfiniteDomainUsesEnabled())
			{
				domainUsesConsumedThisMoon[clientId] = Mathf.Min(GetEffectiveDomainUsesPerMoon(), GetConsumedDomainUses(clientId) + 1);
			}
		}

		private int GetConfiguredDomainUsesPerMoon()
		{
			return Mathf.Clamp(domainUsesPerMoonConfig?.Value ?? 1, 1, 20);
		}

		private int GetEffectiveDomainUsesPerMoon()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && singleton.IsListening && !singleton.IsServer && hostConfigReceived)
			{
				return syncedDomainUsesPerMoon;
			}
			return GetConfiguredDomainUsesPerMoon();
		}

		private bool InfiniteDomainUsesEnabled()
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && singleton.IsListening && !singleton.IsServer && hostConfigReceived)
			{
				return syncedInfiniteDomainUses;
			}
			return infiniteDomainUsesConfig?.Value ?? false;
		}

		private void ShowDomainUsageDenied()
		{
			statusText = "You used all Domain Expansions available on this moon.";
			ShowTip("Domain unavailable", statusText);
			Log.LogInfo((object)statusText);
		}

		private void ShowDomainUnavailableInShip()
		{
			statusText = "You have 0 domain uses while the ship is in orbit.";
			ShowTip("Domain unavailable", statusText);
			Log.LogInfo((object)statusText);
		}

		private void ShowDomainBusy()
		{
			statusText = "You cannot open a domain while you are inside another domain.";
			ShowTip("Domain blocked", statusText);
			Log.LogInfo((object)statusText);
		}

		private void OpenDomainLocal(DomainKind domain, Vector3 center, ulong casterId, bool affectsGameplay, float duration = -1f, Dictionary<int, Vector3>? participants = null, ulong sessionId = 0uL, Vector3? arenaCenter = null)
		{
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			selectedDomain = domain;
			CloseDomain(broadcast: false);
			ClearInfiniteVoidRuntimeReferences();
			domainOpen = true;
			openingActive = true;
			domainVisualBuilt = false;
			domainAffectsGameplay = affectsGameplay;
			openingTime = 0f;
			activeDomainDuration = ((duration > 0f) ? duration : RollDomainDuration(domain));
			domainTimeLeft = activeDomainDuration + 2.35f;
			openingEndRealtime = Time.realtimeSinceStartup + 2.35f;
			domainEndRealtime = openingEndRealtime + activeDomainDuration;
			effectTimer = 0f;
			gambleTimer = 0f;
			jackpotRoll = 0;
			activeDomainSessionId = sessionId;
			domainSourceCenter = center;
			domainCenter = center;
			activeDomainArenaCenter = (Vector3)(((??)arenaCenter) ?? GetPersistentArenaCenter(domain));
			domainParticipantSourcePositions.Clear();
			if (participants != null)
			{
				foreach (KeyValuePair<int, Vector3> participant in participants)
				{
					domainParticipantSourcePositions[participant.Key] = participant.Value;
				}
			}
			domainArenaActivated = false;
			localPlayerInDomainArena = false;
			localPlayerReturnCaptured = false;
			casterClientId = casterId;
			CreateOpeningAnimation();
			PlayDomainSound(domain, center);
			statusText = GetDomainName(domain) + " opening...";
			ShowTip("Domain opening", statusText);
			Log.LogInfo((object)statusText);
		}

		private void CloseDomain(bool broadcast = true)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			ulong num = activeDomainSessionId;
			if (broadcast && num != 0L)
			{
				BroadcastCloseDomain(num);
			}
			if (num != 0L)
			{
				DisableDomainExteriorBarrierColliders(num);
			}
			RestoreRemotePlayerRepresentationsFromArena();
			RestoreEntitiesFromDomainArena();
			RestoreEnemySpeeds();
			RestoreDomainEnvironmentRendering();
			RestoreDomainAtmosphere();
			ClearSoulMeterVisuals();
			ClearInfiniteVoidRuntimeReferences();
			if ((Object)(object)domainRoot != (Object)null)
			{
				Object.Destroy((Object)(object)domainRoot);
				domainRoot = null;
			}
			if (num != 0L)
			{
				DestroyDomainExteriorBarrier(num);
			}
			openingRoot = null;
			domainLight = null;
			domainOpen = false;
			openingActive = false;
			domainVisualBuilt = false;
			domainAffectsGameplay = false;
			domainArenaActivated = false;
			localPlayerInDomainArena = false;
			localPlayerReturnCaptured = false;
			activeDomainSessionId = 0uL;
			activeDomainArenaCenter = Vector3.zero;
			domainParticipantSourcePositions.Clear();
			domainTimeLeft = 0f;
			activeDomainDuration = 0f;
			openingEndRealtime = 0f;
			domainEndRealtime = 0f;
		}

		private void ClearInfiniteVoidRuntimeReferences()
		{
			infiniteVoidRotators.Clear();
			infiniteVoidPulseLines.Clear();
			infiniteVoidParticleSystems.Clear();
			infiniteVoidParticleRates.Clear();
			infiniteVoidOverlayImages.Clear();
			infiniteVoidOverlayRects.Clear();
			malevolentShrineSlashLines.Clear();
			malevolentShrineSlashPhases.Clear();
			malevolentShrineSlashSpeeds.Clear();
			malevolentShrineSlashWidths.Clear();
			malevolentShrineSlashSprites.Clear();
			openingRotators.Clear();
			openingRotationSpeeds.Clear();
			openingTimedParticles.Clear();
			openingParticleStopProgress.Clear();
			idleDeathGambleRotators.Clear();
			idleDeathGambleRotationSpeeds.Clear();
			idleDeathGambleRotationAxes.Clear();
			idleDeathGambleChaseLights.Clear();
			idleDeathGambleChaseScales.Clear();
			infiniteVoidGalaxyRenderer = null;
			activeDomainInteriorRenderer = null;
			shrineMouthRoot = null;
			if ((Object)(object)shrineCameraVfxRoot != (Object)null)
			{
				Object.Destroy((Object)(object)shrineCameraVfxRoot);
				shrineCameraVfxRoot = null;
			}
			if ((Object)(object)domainCameraBackdropRoot != (Object)null)
			{
				Object.Destroy((Object)(object)domainCameraBackdropRoot);
				domainCameraBackdropRoot = null;
			}
			if ((Object)(object)selfEmbodimentHandMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)selfEmbodimentHandMaterial);
				selfEmbodimentHandMaterial = null;
			}
			if ((Object)(object)selfEmbodimentHandAccentMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)selfEmbodimentHandAccentMaterial);
				selfEmbodimentHandAccentMaterial = null;
			}
			if ((Object)(object)selfEmbodimentCrystalMaterial != (Object)null)
			{
				Object.Destroy((Object)(object)selfEmbodimentCrystalMaterial);
				selfEmbodimentCrystalMaterial = null;
			}
			selfEmbodimentCrystalRoot = null;
			selfEmbodimentVisualTime = 0f;
			infiniteVoidVisualTime = 0f;
			malevolentShrineVisualTime = 0f;
			idleDeathGambleVisualTime = 0f;
			idleDeathGambleRollPulse = 0f;
			if ((Object)(object)infiniteVoidOverlayRoot != (Object)null)
			{
				Object.Destroy((Object)(object)infiniteVoidOverlayRoot);
				infiniteVoidOverlayRoot = null;
			}
		}

		private void EnsurePersistentDomainArenas()
		{
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance.localPlayerController == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)instance).GetInstanceID();
			if (arenaRoundInstanceId != instanceID)
			{
				ClearPersistentDomainArenas();
				arenaRoundInstanceId = instanceID;
			}
			else
			{
				bool flag = false;
				foreach (GameObject value in persistentDomainArenas.Values)
				{
					if ((Object)(object)value == (Object)null)
					{
						flag = true;
						break;
					}
				}
				if (flag)
				{
					ClearPersistentDomainArenas();
					arenaRoundInstanceId = instanceID;
				}
			}
			EnsurePersistentDomainArena(DomainKind.InfiniteVoid);
			EnsurePersistentDomainArena(DomainKind.MalevolentShrineClosed);
			EnsurePersistentDomainArena(DomainKind.IdleDeathGamble);
			EnsurePersistentDomainArena(DomainKind.SelfEmbodimentOfPerfection);
		}

		private unsafe void EnsurePersistentDomainArena(DomainKind domain)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_003d: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			if (persistentDomainArenas.TryGetValue(domain, out GameObject value) && (Object)(object)value != (Object)null)
			{
				return;
			}
			Vector3 persistentArenaCenter = GetPersistentArenaCenter(domain);
			GameObject val = new GameObject("Persistent Domain Arena - " + GetDomainName(domain));
			val.transform.position = persistentArenaCenter;
			float arenaFloorSize = GetArenaFloorSize(domain);
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)obj).name = "Persistent Arena Physics Floor";
			obj.transform.SetParent(val.transform, false);
			obj.transform.localPosition = new Vector3(0f, -0.5f, 0f);
			obj.transform.localScale = new Vector3(arenaFloorSize, 1f, arenaFloorSize);
			Renderer component = obj.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.enabled = false;
			}
			int num = 32;
			float num2 = GetClosedBarrierRadius(domain) + 0.55f;
			float num3 = MathF.PI * 2f * num2 / (float)num * 1.12f;
			for (int i = 0; i < num; i++)
			{
				float num4 = (float)i * MathF.PI * 2f / (float)num;
				GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)3);
				((Object)obj2).name = "Persistent Arena Invisible Wall";
				obj2.transform.SetParent(val.transform, false);
				obj2.transform.localPosition = new Vector3(Mathf.Cos(num4) * num2, 4.5f, Mathf.Sin(num4) * num2);
				obj2.transform.localRotation = Quaternion.Euler(0f, (0f - num4) * 57.29578f + 90f, 0f);
				obj2.transform.localScale = new Vector3(num3, 9f, 0.8f);
				Renderer component2 = obj2.GetComponent<Renderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.enabled = false;
				}
			}
			persistentDomainArenas[domain] = val;
			BuildArenaNavMeshes(val, persistentArenaCenter);
			ManualLogSource log = Log;
			string[] obj3 = new string[5]
			{
				"Persistent arena ready: ",
				GetDomainName(domain),
				" at ",
				null,
				null
			};
			Vector3 val2 = persistentArenaCenter;
			obj3[3] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj3[4] = ".";
			log.LogInfo((object)string.Concat(obj3));
		}

		private unsafe void EnsureSessionDomainArena(ulong sessionId, DomainKind domain, Vector3 center)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_004a: 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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			if (domain == DomainKind.MalevolentShrineOpen || sessionId == 0L || (sessionDomainArenas.TryGetValue(sessionId, out GameObject value) && (Object)(object)value != (Object)null))
			{
				return;
			}
			GameObject val = new GameObject("Session Domain Arena " + sessionId + " - " + GetDomainName(domain));
			val.transform.position = center;
			float arenaFloorSize = GetArenaFloorSize(domain);
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)3);
			((Object)obj).name = "Session Arena Physics Floor";
			obj.transform.SetParent(val.transform, false);
			obj.transform.localPosition = new Vector3(0f, -0.65f, 0f);
			obj.transform.localScale = new Vector3(arenaFloorSize, 1f, arenaFloorSize);
			Renderer component = obj.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.enabled = false;
			}
			float num = arenaFloorSize * 0.5f;
			for (int i = 0; i < 4; i++)
			{
				GameObject obj2 = GameObject.CreatePrimitive((PrimitiveType)3);
				((Object)obj2).name = "Session Arena Invisible Wall";
				obj2.transform.SetParent(val.transform, false);
				bool flag = i < 2;
				float num2 = ((i % 2 == 0) ? (-1f) : 1f);
				obj2.transform.localPosition = (flag ? new Vector3(num2 * num, 3.5f, 0f) : new Vector3(0f, 3.5f, num2 * num));
				obj2.transform.localScale = (flag ? new Vector3(1f, 8f, arenaFloorSize) : new Vector3(arenaFloorSize, 8f, 1f));
				Renderer component2 = obj2.GetComponent<Renderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.enabled = false;
				}
			}
			sessionDomainArenas[sessionId] = val;
			BuildArenaNavMeshes(val, center);
			ManualLogSource log = Log;
			string[] obj3 = new string[5]
			{
				"Session arena ",
				sessionId.ToString(),
				" ready at ",
				null,
				null
			};
			Vector3 val2 = center;
			obj3[3] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj3[4] = ".";
			log.LogInfo((object)string.Concat(obj3));
		}

		private void BuildArenaNavMeshes(GameObject arenaRoot, Vector3 center)
		{
			//IL_001c: 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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_005b: 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)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				List<NavMeshBuildSource> list = new List<NavMeshBuildSource>();
				NavMeshBuilder.CollectSources(arenaRoot.transform, -1, (NavMeshCollectGeometry)1, 0, new List<NavMeshBuildMarkup>(), list);
				Bounds val = default(Bounds);
				((Bounds)(ref val))..ctor(center + Vector3.up * 3.5f, new Vector3(66f, 10f, 66f));
				int settingsCount = NavMesh.GetSettingsCount();
				for (int i = 0; i < settingsCount; i++)
				{
					NavMeshData val2 = NavMeshBuilder.BuildNavMeshData(NavMesh.GetSettingsByIndex(i), list, val, Vector3.zero, Quaternion.identity);
					if (!((Object)(object)val2 == (Object)null))
					{
						persistentArenaNavMeshData.Add(val2);
						persistentArenaNavMeshes.Add(NavMesh.AddNavMeshData(val2));
					}
				}
				Log.LogInfo((object)("Persistent arena NavMesh built with " + settingsCount + " agent settings and " + list.Count + " sources."));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not build persistent arena NavMesh: " + ex.Message));
			}
		}

		private void ClearPersistentDomainArenas()
		{
			//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)
			foreach (NavMeshDataInstance persistentArenaNavMesh in persistentArenaNavMeshes)
			{
				NavMeshDataInstance current = persistentArenaNavMesh;
				try
				{
					((NavMeshDataInstance)(ref current)).Remove();
				}
				catch
				{
				}
			}
			persistentArenaNavMeshes.Clear();
			foreach (NavMeshData persistentArenaNavMeshDatum in persistentArenaNavMeshData)
			{
				if ((Object)(object)persistentArenaNavMeshDatum != (Object)null)
				{
					Object.Destroy((Object)(object)persistentArenaNavMeshDatum);
				}
			}
			persistentArenaNavMeshData.Clear();
			foreach (GameObject value in persistentDomainArenas.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)value);
				}
			}
			persistentDomainArenas.Clear();
			foreach (GameObject value2 in sessionDomainArenas.Values)
			{
				if ((Object)(object)value2 != (Object)null)
				{
					Object.Destroy((Object)(object)value2);
				}
			}
			sessionDomainArenas.Clear();
			arenaRoundInstanceId = 0;
		}

		private static Vector3 GetPersistentArenaCenter(DomainKind domain)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			return (Vector3)(domain switch
			{
				DomainKind.InfiniteVoid => new Vector3(8192f, 512f, 8192f), 
				DomainKind.MalevolentShrineClosed => new Vector3(8320f, 512f, 8192f), 
				DomainKind.IdleDeathGamble => new Vector3(8448f, 512f, 8192f), 
				DomainKind.SelfEmbodimentOfPerfection => new Vector3(8576f, 512f, 8192f), 
				_ => Vector3.zero, 
			});
		}

		private static Vector3 GetSessionArenaCenter(ulong sessionId)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			ulong num = ((sessionId == 0L) ? 0 : ((sessionId - 1) % 32));
			float num2 = 8192f + (float)(num % 8) * 128f;
			float num3 = 8704f + (float)(num / 8) * 128f;
			return new Vector3(num2, 512f, num3);
		}

		private unsafe void ActivateClosedDomainArena()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_00a6: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			if (domainArenaActivated || selectedDomain == DomainKind.MalevolentShrineOpen)
			{
				return;
			}
			domainArenaActivated = true;
			Vector3 val = ((activeDomainArenaCenter != Vector3.zero) ? activeDomainArenaCenter : GetPersistentArenaCenter(selectedDomain));
			if (activeDomainSessionId != 0L)
			{
				EnsureSessionDomainArena(activeDomainSessionId, selectedDomain, val);
			}
			else
			{
				EnsurePersistentDomainArenas();
			}
			SyncArenaPhysics();
			TeleportLocalPlayerIntoArena(domainSourceCenter, val);
			TeleportRemotePlayerRepresentationsIntoArena(domainSourceCenter, val);
			if (domainAffectsGameplay)
			{
				TeleportHostEntitiesIntoArena(domainSourceCenter, val);
				if (selectedDomain == DomainKind.SelfEmbodimentOfPerfection)
				{
					InitializeLocalSoulState();
				}
			}
			domainCenter = val;
			ManualLogSource log = Log;
			string[] obj = new string[7]
			{
				"Closed domain arena activated: ",
				GetDomainName(selectedDomain),
				", source=",
				null,
				null,
				null,
				null
			};
			Vector3 val2 = domainSourceCenter;
			obj[3] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj[4] = ", arena=";
			val2 = val;
			obj[5] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
			obj[6] = ".";
			log.LogInfo((object)string.Concat(obj));
		}

		private unsafe void CreateClosedDomainExteriorBarrier(ulong sessionId, DomainKind domain, Vector3 sourceCenter)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			DestroyDomainExteriorBarrier(sessionId);
			if (domain != DomainKind.MalevolentShrineOpen && sessionId != 0L)
			{
				GameObject val = new GameObject("Closed Domain Exterior " + sessionId + " - " + GetDomainName(domain));
				val.transform.position = sourceCenter;
				domainExteriorRoots[sessionId] = val;
				GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
				((Object)obj).name = "Opaque Black Domain Sphere With Hitbox";
				obj.transform.SetParent(val.transform, false);
				obj.transform.localPosition = Vector3.up * 1.2f;
				obj.transform.localScale = Vector3.one * 52f;
				Renderer component = obj.GetComponent<Renderer>();
				ApplyOpaqueBarrierMaterial(component);
				component.shadowCastingMode = (ShadowCastingMode)0;
				component.receiveShadows = false;
				SphereCollider component2 = obj.GetComponent<SphereCollider>();
				((Collider)component2).enabled = false;
				((Collider)component2).isTrigger = false;
				StartRuntimeCoroutine(EnableExteriorColliderAfterTeleport(sessionId, component2));
				ManualLogSource log = Log;
				string[] obj2 = new string[7]
				{
					"Created solid black exterior for session ",
					sessionId.ToString(),
					" at ",
					null,
					null,
					null,
					null
				};
				Vector3 val2 = sourceCenter;
				obj2[3] = ((object)(*(Vector3*)(&val2))/*cast due to .constrained prefix*/).ToString();
				obj2[4] = " with radius ";
				obj2[5] = 26f.ToString();
				obj2[6] = ".";
				log.LogInfo((object)string.Concat(obj2));
			}
		}

		private IEnumerator CreateClosedDomainExteriorBarrierAfterTeleport(ulong sessionId, DomainKind domain, Vector3 sourceCenter)
		{
			//IL_001c: 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)
			yield return (object)new WaitForSecondsRealtime(2.35f);
			if (!knownDomainSessions.TryGetValue(sessionId, out NetworkDomainSession value))
			{
				pendingExteriorBarrierSessions.Remove(sessionId);
				yield break;
			}
			int localPlayerSlot = GetLocalPlayerSlot();
			bool localParticipant = localPlayerSlot != int.MinValue && value.Participants.ContainsKey(localPlayerSlot);
			float waitTime = 0f;
			while (localParticipant && activeDomainSessionId == sessionId && !domainArenaActivated && waitTime < 3f)
			{
				waitTime += Time.unscaledDeltaTime;
				yield return null;
			}
			yield return (object)new WaitForFixedUpdate();
			if (knownDomainSessions.ContainsKey(sessionId))
			{
				CreateClosedDomainExteriorBarrier(sessionId, domain, sourceCenter);
			}
			pendingExteriorBarrierSessions.Remove(sessionId);
		}

		private IEnumerator EnableExteriorColliderAfterTeleport(ulong sessionId, SphereCollider collider)
		{
			yield return (object)new WaitForFixedUpdate();
			yield return (object)new WaitForSecondsRealtime(0.2f);
			if ((Object)(object)collider != (Object)null && knownDomainSessions.ContainsKey(sessionId) && domainExteriorRoots.ContainsKey(sessionId))
			{
				((Collider)collider).enabled = true;
			}
		}

		private void DestroyDomainExteriorBarrier(ulong sessionId)
		{
			if (!domainExteriorRoots.TryGetValue(sessionId, out GameObject value) || (Object)(object)value == (Object)null)
			{
				domainExteriorRoots.Remove(sessionId);
				return;
			}
			DisableDomainExteriorBarrierColliders(sessionId);
			Object.Destroy((Object)(object)value);
			domainExteriorRoots.Remove(sessionId);
		}

		private void DisableDomainExteriorBarrierColliders(ulong sessionId)
		{
			if (!domainExteriorRoots.TryGetValue(sessionId, out GameObject value) || (Object)(object)value == (Object)null)
			{
				return;
			}
			Collider[] componentsInChildren = value.GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.enabled = false;
				}
			}
		}

		private void DestroyAllDomainExteriorBarriers()
		{
			pendingExteriorBarrierSessions.Clear();
			foreach (ulong item in new List<ulong>(domainExteriorRoots.Keys))
			{
				DestroyDomainExteriorBarrier(item);
			}
		}

		private unsafe void TeleportLocalPlayerIntoArena(Vector3 sourceCenter, Vector3 arenaCenter)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null || IsPlayerDead(val))
			{
				return;
			}
			int playerSlot = GetPlayerSlot(val);
			Vector3 value = ((Component)val).transform.position;
			if (domainParticipantSourcePositions.Count > 0)
			{
				if (!domainParticipantSourcePositions.TryGetValue(playerSlot, out value))
				{
					return;
				}
			}
			else if (GetLocalClientId() != casterClientId && !IsWithinArenaCaptureRadius(((Component)val).transform.position, sourceCenter))
			{
				return;
			}
			localPlayerReturnPosition = ((Component)val).transform.position;
			localPlayerReturnRotation = ((Component)val).transform.rotation;
			localPlayerReturnCaptured = true;
			localPlayerInDomainArena = true;
			hasLastLocalPlayerPosition = false;
			Vector3 val2 = MapPlayerPositionIntoArena(value, sourceCenter, arenaCenter, playerSlot, selectedDomain);
			TeleportPlayerSafely(val, val2, ((Component)val).transform.rotation);
			ManualLogSource log = Log;
			string[] obj = new string[5] { "Local player entered domain arena; return=", null, null, null, null };
			Vector3 val3 = localPlayerReturnPosition;
			obj[1] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
			obj[2] = ", target=";
			val3 = val2;
			obj[3] = ((object)(*(Vector3*)(&val3))/*cast due to .constrained prefix*/).ToString();
			obj[4] = ".";
			log.LogInfo((object)string.Concat(obj));
		}

		private void TeleportRemotePlayerRepresentationsIntoArena(Vector3 sourceCenter, Vector3 arenaCenter)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null || domainParticipantSourcePositions.Count == 0)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)instance.localPlayerController) && !IsPlayerDead(val))
				{
					int playerSlot = GetPlayerSlot(val);
					if (domainParticipantSourcePositions.TryGetValue(playerSlot, out var value))
					{
						Vector3 position = MapPlayerPositionIntoArena(value, sourceCenter, arenaCenter, playerSlot, selectedDomain);
						((Component)val).transform.position = position;
						EnsureRemoteParticipantVisible(val);
					}
				}
			}
		}

		private void MaintainRemoteDomainPlayerRepresentations()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (mig