Decompiled source of Risk Hub v1.0.0

plugins/RiskHub.dll

Decompiled 44 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using HG;
using HarmonyLib;
using KinematicCharacterController;
using R2API;
using R2API.Utils;
using Rewired;
using RiskOfOptions;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Achievements;
using RoR2.CharacterAI;
using RoR2.ExpansionManagement;
using RoR2.Networking;
using RoR2.PostProcessing;
using RoR2.Projectile;
using RoR2.Skills;
using RoR2.SurvivorMannequins;
using RoR2.UI;
using RoR2.UI.MainMenu;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.AddressableAssets.ResourceLocators;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace RiskHub;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.tox.riskhub", "Risk Hub", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
	public static Plugin Instance;

	public static readonly Vector3 Origin = new Vector3(0f, 1000f, 0f);

	public const BindingFlags Flags = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

	public ConfigEntry<bool> Enabled;

	public ConfigEntry<bool> PodFirstPerson;

	public ConfigEntry<bool> PodLook;

	public ConfigEntry<bool> QueueTabCursor;

	public ConfigEntry<bool> QueueAutoPickup;

	public ConfigEntry<bool> SkipIntro;

	public ConfigEntry<string> AutoQueuePreset;

	private Harmony harmony;

	private PreGameController lobby;

	public HubWorld room;

	public HubPanels panels;

	private CameraRigController camera;

	private readonly Dictionary<NetworkUser, HubAvatar> avatars = new Dictionary<NetworkUser, HubAvatar>();

	private readonly Dictionary<GameObject, bool> oldUi = new Dictionary<GameObject, bool>();

	private readonly Dictionary<Camera, bool> oldCameras = new Dictionary<Camera, bool>();

	private float scanAt;

	private float lobbyDiscoveryAt;

	private int lobbyDiscoveries;

	private int escapeFrame = -1;

	private bool previousPauseAbility;

	private VoteController hubVotes;

	private bool previousRevoke;

	private bool previousChange;

	private bool initialized;

	private bool departing;

	private object queueDocument;

	public string Message = string.Empty;

	private readonly Dictionary<NetworkUser, float> staleSince = new Dictionary<NetworkUser, float>();

	public static bool Active => Object.op_Implicit((Object)(object)Instance) && Object.op_Implicit((Object)(object)Instance.room) && Object.op_Implicit((Object)(object)PreGameController.instance) && !HubServices.MissionActive;

	public LocalUser User => (LocalUserManager.readOnlyLocalUsersList.Count <= 0) ? null : LocalUserManager.readOnlyLocalUsersList[0];

	public CharacterBody Body => (User == null) ? null : User.cachedBody;

	public CameraRigController Camera => camera;

	public bool Departing => departing;

	public string InteractionHint
	{
		get
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			LocalUser user = User;
			if (user == null || user.inputPlayer == null)
			{
				return "INTERAGIEREN";
			}
			Player inputPlayer = user.inputPlayer;
			Controller val = (Controller)((!Object.op_Implicit((Object)(object)user.eventSystem) || (int)user.eventSystem.currentInputSource != 1) ? ((object)inputPlayer.controllers.Keyboard) : ((object)inputPlayer.controllers.GetLastActiveController((ControllerType)2)));
			ActionElementMap val2 = ((val == null) ? null : inputPlayer.controllers.maps.GetFirstElementMapWithAction(val, 5, true));
			if (val2 == null && inputPlayer.controllers.Mouse != null)
			{
				val2 = inputPlayer.controllers.maps.GetFirstElementMapWithAction((Controller)(object)inputPlayer.controllers.Mouse, 5, true);
			}
			return (val2 == null) ? "INTERAGIEREN" : ("[ " + val2.elementIdentifierName + " ]");
		}
	}

	public bool Ready
	{
		get
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			if (User == null || !Object.op_Implicit((Object)(object)User.currentNetworkUser) || !Object.op_Implicit((Object)(object)lobby))
			{
				return false;
			}
			VoteController component = ((Component)lobby).GetComponent<VoteController>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return false;
			}
			for (int i = 0; i < component.GetVoteCount(); i++)
			{
				UserVote vote = component.GetVote(i);
				if ((Object)(object)vote.networkUserObject == (Object)(object)((Component)User.currentNetworkUser).gameObject && vote.voteChoiceIndex == 0)
				{
					return true;
				}
			}
			return false;
		}
	}

	private void Awake()
	{
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected O, but got Unknown
		//IL_036f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Expected O, but got Unknown
		//IL_0421: Unknown result type (might be due to invalid IL or missing references)
		//IL_0427: Expected O, but got Unknown
		//IL_044b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0455: Expected O, but got Unknown
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Expected O, but got Unknown
		Instance = this;
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Hub", "Enabled", true, "Begehbare Kommandozentrale statt Charakterauswahl.");
		PodFirstPerson = ((BaseUnityPlugin)this).Config.Bind<bool>("Hub", "FirstPersonPods", true, "Ankunft in der nativen Landekapsel aus First Person.");
		PodLook = ((BaseUnityPlugin)this).Config.Bind<bool>("Hub", "LookAroundInPods", true, "Freies Umschauen in der nativen Landekapsel.");
		AutoQueuePreset = ((BaseUnityPlugin)this).Config.Bind<string>("Queue", "AutoLoadPreset", string.Empty, "(veraltet, wird nicht mehr genutzt)");
		QueueAutoPickup = ((BaseUnityPlugin)this).Config.Bind<bool>("Queue", "AutoPickup", true, "Command-Essenzen in der Nähe automatisch aufsammeln, wenn die Queue für diese Seltenheit ein Item hat.");
		QueueTabCursor = ((BaseUnityPlugin)this).Config.Bind<bool>("Queue", "TabCursor", true, "Mauszeiger im TAB-Menü einblenden, um Queue-Loadouts im Run zu wechseln.");
		SkipIntro = ((BaseUnityPlugin)this).Config.Bind<bool>("Hub", "SkipIntro", true, "Logo und Intro überspringen: direkt ins Hauptmenü, sobald das Spiel geladen ist.");
		RegisterOptions();
		harmony = new Harmony("com.tox.riskhub");
		HubSkipIntro.Register(harmony);
		HubNightmare.Register(harmony);
		HubPartyScale.Register(harmony);
		HubQueue.Register(harmony, ((Component)this).gameObject);
		HubVotes.Register(((Component)this).gameObject);
		harmony.PatchAll(typeof(Plugin));
		harmony.PatchAll(typeof(HubMainMenuPatch));
		harmony.PatchAll(typeof(HubHostOnlyVotes));
		harmony.PatchAll(typeof(HubMenuLobbyRedirect));
		harmony.PatchAll(typeof(HubLateLobbyUI));
		HubVoteWriteDedup.Install(harmony);
		((Component)this).gameObject.AddComponent<HubMenuReturn>();
		((Component)this).gameObject.AddComponent<HubKickedGuest>();
		harmony.PatchAll(typeof(HubKickPatch));
		harmony.PatchAll(typeof(HubKickSignal));
		harmony.PatchAll(typeof(HubPauseMenuPatch));
		((Component)this).gameObject.AddComponent<HubNativeInteraction>();
		harmony.PatchAll(typeof(HubPauseControl));
		harmony.PatchAll(typeof(HubScoreboard));
		harmony.PatchAll(typeof(HubInvitePause));
		((Component)this).gameObject.AddComponent<HubSoloPause>();
		((Component)this).gameObject.AddComponent<HubAudio>();
		((Component)this).gameObject.AddComponent<HubTestItems>();
		((Component)this).gameObject.AddComponent<HubHudVisibility>();
		harmony.PatchAll(typeof(HubHideBuildId));
		harmony.PatchAll(typeof(HubLocalUnlocks));
		harmony.PatchAll(typeof(HubPracticePickups));
		HubMainMenuPatch.ConfigureQuickRestart();
		harmony.PatchAll(typeof(HubCapsules));
		harmony.PatchAll(typeof(HubServices));
		harmony.PatchAll(typeof(HubTrainingRewards));
		harmony.PatchAll(typeof(HubPracticeProfile));
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(ProtectPracticeAchievements));
		Harmony obj = harmony;
		MethodInfo methodInfo = AccessTools.Method(typeof(CharacterMaster), "OnBodyStart", (Type[])null, (Type[])null);
		HarmonyMethod val = new HarmonyMethod(typeof(HubServices), "MasterDifficulty", (Type[])null);
		obj.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
		Type type = AccessTools.TypeByName("LookingGlass.StatsDisplay.StatsDisplayClass");
		if (type != null)
		{
			harmony.Patch((MethodBase)AccessTools.Method(type, "CalculateStuff", (Type[])null, (Type[])null), new HarmonyMethod(typeof(HubServices), "StatsHudReady", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		((Component)this).gameObject.AddComponent<HubCapsules>();
		((Component)this).gameObject.AddComponent<HubLaunchPlatform>();
		Harmony obj2 = harmony;
		methodInfo = AccessTools.Method(typeof(CharacterMaster), "SpawnBody", new Type[1] { typeof(SpawnBodyArgs) }, (Type[])null);
		val = new HarmonyMethod(typeof(Plugin), "SpawnPatch", (Type[])null);
		obj2.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
		NetworkUser.onLoadoutChangedGlobal += Changed;
		NetworkUser.onNetworkUserBodyPreferenceChanged += new NetworkUserGenericDelegate(Preference);
		Run.onRunStartGlobal += RunStarted;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Risk Hub 0.5.32 private alpha loaded");
	}

	public void LoggerForHall(string text)
	{
		((BaseUnityPlugin)this).Logger.LogWarning((object)text);
	}

	private void ProtectPracticeAchievements()
	{
		harmony.PatchAll(typeof(HubPracticeAchievementCallbacks));
	}

	private void RegisterOptions()
	{
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Expected O, but got Unknown
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Expected O, but got Unknown
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010e: Expected O, but got Unknown
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Expected O, but got Unknown
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		using (Stream stream = executingAssembly.GetManifestResourceStream("RiskHub.Icon.png"))
		{
			if (stream != null)
			{
				byte[] array = new byte[(int)stream.Length];
				int num;
				for (int i = 0; i < array.Length; i += num)
				{
					num = stream.Read(array, i, array.Length - i);
					if (num == 0)
					{
						break;
					}
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				ImageConversion.LoadImage(val, array);
				ModSettingsManager.SetModIcon(Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f)), "com.tox.riskhub", "Risk Hub");
			}
		}
		OptLoc.Token("RISKHUB_ROO_MOD_DESC", "Begehbare Kommandozentrale mit Missionskontrolle, Ausrüstung, Crew, Command Queue und Trainingsziel.", "Walkable command center with mission control, loadout, crew, Command Queue and training target.");
		ModSettingsManager.SetModDescriptionToken("RISKHUB_ROO_MOD_DESC", "com.tox.riskhub", "Risk Hub");
		CheckBoxOption val2 = new CheckBoxOption(Enabled);
		CheckBoxOption val3 = new CheckBoxOption(QueueAutoPickup);
		CheckBoxOption val4 = new CheckBoxOption(QueueTabCursor);
		CheckBoxOption val5 = new CheckBoxOption(SkipIntro);
		ModSettingsManager.AddOption((BaseOption)(object)val5, "com.tox.riskhub", "Risk Hub");
		OptLoc.Add(val5, "Intro überspringen", "Skip intro", "Logo und Intro überspringen: direkt ins Hauptmenü, sobald das Spiel geladen ist.", "Skip the logos and intro: go straight to the main menu as soon as the game has loaded.");
		CheckBoxOption val6 = new CheckBoxOption(PodFirstPerson);
		ModSettingsManager.AddOption((BaseOption)(object)val2, "com.tox.riskhub", "Risk Hub");
		ModSettingsManager.AddOption((BaseOption)(object)val3, "com.tox.riskhub", "Risk Hub");
		ModSettingsManager.AddOption((BaseOption)(object)val4, "com.tox.riskhub", "Risk Hub");
		ModSettingsManager.AddOption((BaseOption)(object)val6, "com.tox.riskhub", "Risk Hub");
		OptLoc.Add(val2, "Hub aktiv", "Hub enabled", "Begehbare Kommandozentrale statt Charakterauswahl.", "Walkable command center instead of the character select screen.");
		OptLoc.Add(val3, "Auto-Aufsammeln", "Auto pickup", "Command-Essenzen in der Nähe automatisch aufsammeln, wenn die Queue für diese Seltenheit ein Item hat.", "Automatically pick up nearby Command essences when the queue has an item for that rarity.");
		OptLoc.Add(val4, "Mauszeiger im TAB-Menü", "Cursor in TAB menu", "Mauszeiger im TAB-Menü einblenden, um Queue-Loadouts im Run zu wechseln.", "Show the mouse cursor in the TAB menu to switch queue loadouts during a run.");
		OptLoc.Add(val6, "Kapsel in First Person", "First-person pods", "Ankunft in der nativen Landekapsel aus First Person.", "Arrive in the native drop pod in first person.");
		OptLoc.Category("com.tox.riskhub", "Hub", "Hub", "Hub");
		OptLoc.Category("com.tox.riskhub", "Queue", "Queue", "Queue");
		RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(OptLoc.Apply));
		OptLoc.Apply();
	}

	private void OnDestroy()
	{
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(ProtectPracticeAchievements));
		NetworkUser.onLoadoutChangedGlobal -= Changed;
		NetworkUser.onNetworkUserBodyPreferenceChanged -= new NetworkUserGenericDelegate(Preference);
		Run.onRunStartGlobal -= RunStarted;
		Teardown();
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}

	private void FixedUpdate()
	{
		if (Active)
		{
			HubServices.Tick();
		}
	}

	private void Update()
	{
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0445: Unknown result type (might be due to invalid IL or missing references)
		//IL_046e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0473: Unknown result type (might be due to invalid IL or missing references)
		//IL_0478: Unknown result type (might be due to invalid IL or missing references)
		//IL_051b: Unknown result type (might be due to invalid IL or missing references)
		if (!Enabled.Value || HubServices.MissionActive || !Object.op_Implicit((Object)(object)PreGameController.instance))
		{
			if (Object.op_Implicit((Object)(object)room))
			{
				Teardown();
			}
			return;
		}
		if ((Object)(object)lobby != (Object)(object)PreGameController.instance)
		{
			Teardown();
			lobby = PreGameController.instance;
			hubVotes = ((Component)lobby).GetComponent<VoteController>();
			if (Object.op_Implicit((Object)(object)hubVotes))
			{
				previousRevoke = hubVotes.canRevokeVote;
				previousChange = hubVotes.canChangeVote;
				hubVotes.canRevokeVote = true;
				hubVotes.canChangeVote = true;
			}
			previousPauseAbility = PauseManager.IsAbleToPause;
			PauseManager.IsAbleToPause = true;
			lobbyDiscoveries = 0;
			lobbyDiscoveryAt = 0f;
			HubCapsules.ArrivalSession = false;
			room = ((Component)this).gameObject.AddComponent<HubWorld>();
			HubServices.Begin();
			room.Build();
			((MonoBehaviour)this).StartCoroutine(ArtifactCodes.Prepare());
			panels = ((Component)this).gameObject.AddComponent<HubPanels>();
			panels.Build(this);
			Message = HubLoc.Tr("Willkommen in der Kommandozentrale");
			initialized = false;
			departing = false;
			scanAt = 0f;
		}
		if (User == null || !Object.op_Implicit((Object)(object)User.currentNetworkUser))
		{
			return;
		}
		if (!initialized)
		{
			UserProfile userProfile = User.userProfile;
			HubLocalUnlocks.EnforceSavedLoadout(userProfile);
			string text = ((userProfile == null) ? "local" : userProfile.fileName);
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Profiles", text + ".Visited", false, "Kommandozentrale bereits betreten.");
			if (!val.Value)
			{
				userProfile.SetSurvivorPreference(SurvivorCatalog.FindSurvivorDef("Commando"));
				userProfile.RequestEventualSave();
				val.Value = true;
				((BaseUnityPlugin)this).Config.Save();
			}
			SurvivorDef survivorPreference = userProfile.GetSurvivorPreference();
			if (Object.op_Implicit((Object)(object)survivorPreference) && userProfile.HasSurvivorUnlocked(survivorPreference.survivorIndex))
			{
				User.currentNetworkUser.SetSurvivorPreferenceClient(survivorPreference);
			}
			initialized = true;
		}
		if (Time.unscaledTime >= scanAt)
		{
			scanAt = Time.unscaledTime + 0.35f;
			if (NetworkServer.active && !departing)
			{
				ServerAvatars();
			}
			HideLobby();
		}
		if (Object.op_Implicit((Object)(object)Body) && !Object.op_Implicit((Object)(object)camera))
		{
			GameObject val2 = Object.Instantiate<GameObject>(LegacyResourcesAPI.Load<GameObject>("Prefabs/Main Camera"));
			((Object)val2).name = "RiskHubPlayerCamera";
			camera = val2.GetComponent<CameraRigController>();
			camera.createHud = true;
			Behaviour[] componentsInChildren = ((Component)camera).GetComponentsInChildren<Behaviour>(true);
			foreach (Behaviour val3 in componentsInChildren)
			{
				if (((object)val3).GetType().FullName == "UnityEngine.Rendering.PostProcessing.PostProcessLayer")
				{
					val3.enabled = false;
				}
			}
			CameraRigControllerSpectateControls component = ((Component)camera).GetComponent<CameraRigControllerSpectateControls>();
			if (Object.op_Implicit((Object)(object)component))
			{
				((Behaviour)component).enabled = false;
			}
			camera.viewer = User.currentNetworkUser;
			camera.nextTarget = ((Component)Body).gameObject;
			typeof(CameraRigController).GetProperty("target", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).SetValue(camera, ((Component)Body).gameObject, null);
		}
		if (!Object.op_Implicit((Object)(object)Body) || !Object.op_Implicit((Object)(object)camera))
		{
			return;
		}
		User.currentNetworkUser.cameraRigController = camera;
		camera.nextTarget = ((Component)Body).gameObject;
		if ((Object)(object)camera.target != (Object)(object)((Component)Body).gameObject)
		{
			typeof(CameraRigController).GetProperty("target", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).SetValue(camera, ((Component)Body).gameObject, null);
		}
		if (!HubWorld.InsideRoom(Body.footPosition) && NetworkServer.active)
		{
			((BaseCharacterController)Body.characterMotor).Motor.SetPosition(Origin + HubLayout.SpawnPoint, true);
		}
		if (Input.GetKeyDown((KeyCode)27))
		{
			HandleEscape();
		}
		else
		{
			if (panels.IsOpen || departing || User.isUIFocused || User.inputPlayer == null || !User.inputPlayer.GetButtonDown(5))
			{
				return;
			}
			if (HubLocalUnlocks.Targeted())
			{
				HubLocalUnlocks.Activate();
				return;
			}
			if (HubExitDoor.Targeted())
			{
				HubExitDoor.Activate();
				return;
			}
			Station station = room.Closest(Body.footPosition);
			if (station != null)
			{
				panels.Open(station.Kind);
			}
		}
	}

	public void StartDeparture()
	{
		departing = true;
		queueDocument = null;
		if (Object.op_Implicit((Object)(object)panels))
		{
			panels.Close();
		}
	}

	public void HandleEscape()
	{
		if (Active && Object.op_Implicit((Object)(object)panels) && Time.frameCount != escapeFrame)
		{
			PauseManager.TogglePauseScreen();
		}
	}

	[HarmonyPatch(typeof(PauseManager), "TogglePauseScreen")]
	[HarmonyPrefix]
	private static bool HubEscape()
	{
		if (!Active)
		{
			return true;
		}
		Plugin instance = Instance;
		if (Time.frameCount == instance.escapeFrame)
		{
			return false;
		}
		instance.escapeFrame = Time.frameCount;
		if (Object.op_Implicit((Object)(object)instance.panels) && instance.panels.IsOpen)
		{
			instance.panels.Close();
			return false;
		}
		return true;
	}

	private void ServerAvatars()
	{
		//IL_0377: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Invalid comparison between Unknown and I4
		//IL_04b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b9: Invalid comparison between Unknown and I4
		foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
		{
			if (!Object.op_Implicit((Object)(object)readOnlyInstances) || (avatars.TryGetValue(readOnlyInstances, out var value) && Object.op_Implicit((Object)(object)value) && Object.op_Implicit((Object)(object)value.Master)))
			{
				continue;
			}
			NetworkConnection connectionToClient = ((NetworkBehaviour)readOnlyInstances).connectionToClient;
			if (connectionToClient != null && !connectionToClient.isReady)
			{
				continue;
			}
			if (Object.op_Implicit((Object)(object)readOnlyInstances.masterObject))
			{
				if (Object.op_Implicit((Object)(object)readOnlyInstances.masterObject.GetComponent<HubAvatar>()))
				{
					continue;
				}
				CharacterMaster component = readOnlyInstances.masterObject.GetComponent<CharacterMaster>();
				if (!staleSince.TryGetValue(readOnlyInstances, out var value2))
				{
					staleSince[readOnlyInstances] = Time.unscaledTime;
					continue;
				}
				if (Time.unscaledTime - value2 < 1.5f || (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.GetBody())))
				{
					continue;
				}
				staleSince.Remove(readOnlyInstances);
				readOnlyInstances.masterObject = null;
				if (Object.op_Implicit((Object)(object)component))
				{
					NetworkServer.Destroy(((Component)component).gameObject);
				}
			}
			GameObject val = Object.Instantiate<GameObject>(LegacyResourcesAPI.Load<GameObject>("Prefabs/CharacterMasters/CommandoMaster"));
			((Object)val).name = "RiskHubTemporaryMaster";
			value = val.AddComponent<HubAvatar>();
			value.User = readOnlyInstances;
			value.Master = val.GetComponent<CharacterMaster>();
			avatars[readOnlyInstances] = value;
			NetworkServer.Spawn(val);
			value.Respawning = true;
			val.GetComponent<PlayerCharacterMasterController>().LinkToNetworkUserServer(readOnlyInstances);
			value.Respawning = false;
			Respawn(value);
			if (connectionToClient != null && (Object)(object)readOnlyInstances != (Object)(object)((User == null) ? null : User.currentNetworkUser))
			{
				((MonoBehaviour)this).StartCoroutine(Relink(value));
			}
		}
		List<NetworkUser> list = new List<NetworkUser>();
		foreach (KeyValuePair<NetworkUser, HubAvatar> avatar in avatars)
		{
			if (!Object.op_Implicit((Object)(object)avatar.Key))
			{
				DestroyAvatar(avatar.Value);
				list.Add(avatar.Key);
			}
		}
		foreach (NetworkUser item in list)
		{
			avatars.Remove(item);
		}
		HashSet<CharacterMaster> hashSet = new HashSet<CharacterMaster>();
		foreach (KeyValuePair<NetworkUser, HubAvatar> avatar2 in avatars)
		{
			if (Object.op_Implicit((Object)(object)avatar2.Key) && Object.op_Implicit((Object)(object)avatar2.Value) && Object.op_Implicit((Object)(object)avatar2.Value.Master))
			{
				hashSet.Add(avatar2.Value.Master);
			}
		}
		foreach (CharacterMaster item2 in new List<CharacterMaster>(CharacterMaster.readOnlyInstancesList))
		{
			if (Object.op_Implicit((Object)(object)item2) && !hashSet.Contains(item2) && (int)item2.teamIndex == 1)
			{
				PlayerCharacterMasterController component2 = ((Component)item2).GetComponent<PlayerCharacterMasterController>();
				bool flag;
				if (Object.op_Implicit((Object)(object)component2))
				{
					flag = !Object.op_Implicit((Object)(object)component2.networkUser) || Object.op_Implicit((Object)(object)((Component)item2).GetComponent<HubAvatar>());
				}
				else
				{
					CharacterMaster val2 = ((!Object.op_Implicit((Object)(object)item2.minionOwnership)) ? null : item2.minionOwnership.ownerMaster);
					flag = !Object.op_Implicit((Object)(object)val2) || !hashSet.Contains(val2);
				}
				if (flag)
				{
					((BaseUnityPlugin)this).Logger.LogDebug((object)("RiskHub: verwaister Spieler-Rest entfernt: " + ((Object)item2).name));
					item2.DestroyBody();
					NetworkServer.Destroy(((Component)item2).gameObject);
				}
			}
		}
		foreach (CharacterBody item3 in new List<CharacterBody>(CharacterBody.readOnlyInstancesList))
		{
			if (Object.op_Implicit((Object)(object)item3) && !Object.op_Implicit((Object)(object)item3.master) && Object.op_Implicit((Object)(object)item3.teamComponent) && (int)item3.teamComponent.teamIndex == 1)
			{
				if (Object.op_Implicit((Object)(object)((Component)item3).GetComponent<NetworkIdentity>()))
				{
					NetworkServer.Destroy(((Component)item3).gameObject);
				}
				else
				{
					Object.Destroy((Object)(object)((Component)item3).gameObject);
				}
			}
		}
		if (Object.op_Implicit((Object)(object)room) && !Object.op_Implicit((Object)(object)room.Dummy) && !room.DummyInitialized)
		{
			room.CreateDummy();
		}
	}

	private IEnumerator Relink(HubAvatar avatar)
	{
		yield return (object)new WaitForSecondsRealtime(2.5f);
		if (Object.op_Implicit((Object)(object)avatar) && Object.op_Implicit((Object)(object)avatar.User) && Object.op_Implicit((Object)(object)avatar.Master) && Active && NetworkServer.active && !departing)
		{
			NetworkUser user = avatar.User;
			user.masterObject = null;
			yield return null;
			if (Object.op_Implicit((Object)(object)avatar) && Object.op_Implicit((Object)(object)avatar.Master))
			{
				avatar.Respawning = true;
				((Component)avatar.Master).GetComponent<PlayerCharacterMasterController>().LinkToNetworkUserServer(user);
				avatar.Respawning = false;
				Respawn(avatar);
			}
		}
	}

	private static void RemoveMinions(CharacterMaster owner)
	{
		if (!NetworkServer.active || !Object.op_Implicit((Object)(object)owner))
		{
			return;
		}
		foreach (CharacterMaster item in new List<CharacterMaster>(CharacterMaster.readOnlyInstancesList))
		{
			if (Object.op_Implicit((Object)(object)item) && !((Object)(object)item == (Object)(object)owner) && Object.op_Implicit((Object)(object)item.minionOwnership) && !((Object)(object)item.minionOwnership.ownerMaster != (Object)(object)owner))
			{
				try
				{
					item.DestroyBody();
					NetworkServer.Destroy(((Component)item).gameObject);
				}
				catch
				{
				}
			}
		}
	}

	private void Respawn(HubAvatar avatar)
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: 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_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkServer.active || !Object.op_Implicit((Object)(object)avatar) || !Object.op_Implicit((Object)(object)avatar.Master) || departing || avatar.Respawning)
		{
			return;
		}
		avatar.Respawning = true;
		Vector3 val = Origin + HubLayout.SpawnPoint;
		CharacterBody body = avatar.Master.GetBody();
		if (Object.op_Implicit((Object)(object)body) && HubWorld.InsideRoom(body.footPosition))
		{
			val = body.footPosition + Vector3.up * 0.1f;
		}
		RemoveMinions(avatar.Master);
		avatar.Master.DestroyBody();
		avatar.Master.bodyPrefab = BodyCatalog.GetBodyPrefab(avatar.User.bodyIndexPreference);
		if (!Object.op_Implicit((Object)(object)avatar.Master.bodyPrefab))
		{
			avatar.Master.bodyPrefab = BodyCatalog.FindBodyPrefab("CommandoBody");
		}
		avatar.User.CopyLoadoutToMaster();
		CharacterBody val2 = avatar.Master.SpawnBody(val, Quaternion.identity);
		if (Object.op_Implicit((Object)(object)val2))
		{
			if (Object.op_Implicit((Object)(object)val2.equipmentSlot))
			{
				((Behaviour)val2.equipmentSlot).enabled = false;
			}
			val2.AddBuff(Buffs.HiddenInvincibility);
			EntityStateMachine val3 = EntityStateMachine.FindByCustomName(((Component)val2).gameObject, "Body");
			if ((Object)(object)val3 != (Object)null)
			{
				val3.SetNextStateToMain();
			}
		}
		avatar.Respawning = false;
	}

	private void Changed(NetworkUser user)
	{
		if (Active && NetworkServer.active && avatars.TryGetValue(user, out var value) && !value.Respawning)
		{
			value.Respawning = true;
			((MonoBehaviour)this).StartCoroutine(RespawnAfterPreference(value));
		}
	}

	private IEnumerator RespawnAfterPreference(HubAvatar avatar)
	{
		yield return null;
		if (Object.op_Implicit((Object)(object)avatar))
		{
			avatar.Respawning = false;
			if (Active && NetworkServer.active && !departing && Object.op_Implicit((Object)(object)avatar.User))
			{
				Respawn(avatar);
			}
		}
	}

	private void Preference(NetworkUser user)
	{
		Changed(user);
	}

	public void RediscoverLobby()
	{
		lobbyDiscoveryAt = 0f;
	}

	private void HideLobby()
	{
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0257: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_037e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0384: Invalid comparison between Unknown and I4
		if (!Object.op_Implicit((Object)(object)Body) || !Object.op_Implicit((Object)(object)camera) || !Object.op_Implicit((Object)(object)camera.hud))
		{
			return;
		}
		foreach (KeyValuePair<GameObject, bool> item in oldUi)
		{
			if (Object.op_Implicit((Object)(object)item.Key) && item.Key.activeSelf)
			{
				item.Key.SetActive(false);
			}
		}
		foreach (KeyValuePair<Camera, bool> oldCamera in oldCameras)
		{
			if (Object.op_Implicit((Object)(object)oldCamera.Key) && ((Behaviour)oldCamera.Key).enabled)
			{
				((Behaviour)oldCamera.Key).enabled = false;
			}
		}
		if (Time.unscaledTime < lobbyDiscoveryAt)
		{
			return;
		}
		lobbyDiscoveries++;
		lobbyDiscoveryAt = Time.unscaledTime + ((lobbyDiscoveries >= 4) ? 2f : 0.5f);
		object obj = Get(lobby, "lobbyBackground");
		GameObject val = (GameObject)((obj is GameObject) ? obj : null);
		if (Object.op_Implicit((Object)(object)val))
		{
			if (!oldUi.ContainsKey(val))
			{
				oldUi[val] = val.activeSelf;
			}
			val.SetActive(false);
		}
		CharacterSelectController[] array = Object.FindObjectsOfType<CharacterSelectController>(true);
		foreach (CharacterSelectController val2 in array)
		{
			Scene scene = ((Component)val2).gameObject.scene;
			if (!((Scene)(ref scene)).IsValid())
			{
				continue;
			}
			Canvas componentInParent = ((Component)val2).GetComponentInParent<Canvas>();
			if ((Object)(object)((Component)val2).gameObject != (Object)(object)((Component)this).gameObject)
			{
				GameObject gameObject = ((Component)val2).gameObject;
				if (!oldUi.ContainsKey(gameObject))
				{
					oldUi[gameObject] = gameObject.activeSelf;
				}
				gameObject.SetActive(false);
			}
		}
		SurvivorMannequinSlotController[] array2 = Object.FindObjectsOfType<SurvivorMannequinSlotController>(true);
		foreach (SurvivorMannequinSlotController val3 in array2)
		{
			Scene scene2 = ((Component)val3).gameObject.scene;
			if (((Scene)(ref scene2)).IsValid())
			{
				GameObject gameObject2 = ((Component)val3).gameObject;
				if (!oldUi.ContainsKey(gameObject2))
				{
					oldUi[gameObject2] = gameObject2.activeSelf;
				}
				gameObject2.SetActive(false);
			}
		}
		Camera[] array3 = Object.FindObjectsOfType<Camera>();
		foreach (Camera val4 in array3)
		{
			if ((!Object.op_Implicit((Object)(object)camera) || (!((Component)val4).transform.IsChildOf(((Component)camera).transform) && !((Object)(object)val4 == (Object)(object)camera.sceneCam) && !((Object)(object)val4 == (Object)(object)camera.uiCam) && !((Object)(object)val4 == (Object)(object)camera.skyboxCam))) && !((Object)val4).name.StartsWith("ToX_", StringComparison.Ordinal) && ((Object)val4).name.IndexOf("RiskHub", StringComparison.OrdinalIgnoreCase) < 0 && (int)val4.cameraType == 1 && !Object.op_Implicit((Object)(object)((Component)val4).GetComponentInParent<CameraRigController>()) && !Object.op_Implicit((Object)(object)((Component)val4).GetComponentInParent<Canvas>()))
			{
				if (!oldCameras.ContainsKey(val4))
				{
					oldCameras[val4] = ((Behaviour)val4).enabled;
				}
				((Behaviour)val4).enabled = false;
			}
		}
	}

	public CharacterSelectController Selection()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		CharacterSelectController[] array = Object.FindObjectsOfType<CharacterSelectController>(true);
		foreach (CharacterSelectController val in array)
		{
			Scene scene = ((Component)val).gameObject.scene;
			if (((Scene)(ref scene)).IsValid() && Get(val, "localUser") == User)
			{
				return val;
			}
		}
		return null;
	}

	public void ToggleReady()
	{
		if (User != null && Object.op_Implicit((Object)(object)User.currentNetworkUser) && Object.op_Implicit((Object)(object)lobby))
		{
			User.currentNetworkUser.CallCmdSubmitVote(((Component)lobby).gameObject, Ready ? (-1) : 0);
		}
	}

	public void Vote(RuleChoiceDef choice)
	{
		if (!Active || choice == null || User == null)
		{
			return;
		}
		if (!NetworkServer.active)
		{
			Message = HubLoc.Tr("Nur der Host ändert die Run-Einstellungen.");
			return;
		}
		RuleChoiceMask resolvedRuleChoiceMask = lobby.resolvedRuleChoiceMask;
		if (resolvedRuleChoiceMask == null || ((SerializableBitArray)resolvedRuleChoiceMask)[choice.globalIndex])
		{
			PreGameRuleVoteController val = PreGameRuleVoteController.FindForUser(User.currentNetworkUser);
			if (Object.op_Implicit((Object)(object)val))
			{
				val.SetVote(choice.ruleDef.globalIndex, choice.localIndex);
			}
		}
	}

	public void SelectSurvivor(SurvivorDef survivor)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if (User != null && Object.op_Implicit((Object)(object)survivor) && User.userProfile.HasSurvivorUnlocked(survivor.survivorIndex))
		{
			User.userProfile.SetSurvivorPreference(survivor);
			User.userProfile.RequestEventualSave();
			User.currentNetworkUser.SetSurvivorPreferenceClient(survivor);
		}
	}

	public void SetSkill(GenericSkill skill, uint variant)
	{
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Expected O, but got Unknown
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)Body) || !Object.op_Implicit((Object)(object)skill) || User == null)
		{
			return;
		}
		int skillSlotIndex = Body.skillLocator.GetSkillSlotIndex(skill);
		if (skillSlotIndex >= 0 && variant < skill.skillFamily.variants.Length)
		{
			Variant val = skill.skillFamily.variants[variant];
			if (!Object.op_Implicit((Object)(object)val.unlockableDef) || User.userProfile.HasUnlockable(val.unlockableDef))
			{
				Loadout val2 = new Loadout();
				User.userProfile.CopyLoadout(val2);
				val2.bodyLoadoutManager.SetSkillVariant(Body.bodyIndex, skillSlotIndex, variant);
				User.userProfile.SetLoadout(val2);
				AccessTools.Method(typeof(NetworkUser), "PullLoadoutFromUserProfile", (Type[])null, (Type[])null).Invoke(User.currentNetworkUser, null);
			}
		}
	}

	public void ApplySelection(SurvivorDef survivor, Loadout draft)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		if (User != null && Object.op_Implicit((Object)(object)survivor) && User.userProfile.HasSurvivorUnlocked(survivor.survivorIndex))
		{
			draft.EnforceUnlockables(User.userProfile);
			User.userProfile.SetLoadout(draft);
			User.userProfile.SetSurvivorPreference(survivor);
			User.userProfile.RequestEventualSave();
			User.currentNetworkUser.SetSurvivorPreferenceClient(survivor);
			AccessTools.Method(typeof(NetworkUser), "PullLoadoutFromUserProfile", (Type[])null, (Type[])null).Invoke(User.currentNetworkUser, null);
		}
	}

	public void Invite()
	{
		if (PlatformSystems.lobbyManager.CanInvite())
		{
			PlatformSystems.lobbyManager.OpenInviteOverlay();
		}
		else
		{
			Message = HubLoc.Tr("Einladen ist in dieser Lobby nicht verfügbar.");
		}
	}

	public void Kick(NetworkUser user)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//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)
		if (!NetworkServer.active || !Object.op_Implicit((Object)(object)user) || User == null || (Object)(object)user == (Object)(object)User.currentNetworkUser)
		{
			return;
		}
		NetworkConnection connectionToClient = ((NetworkBehaviour)user).connectionToClient;
		if (connectionToClient != null && connectionToClient != ((NetworkBehaviour)User.currentNetworkUser).connectionToClient)
		{
			try
			{
				SimpleChatMessage val = new SimpleChatMessage();
				val.baseToken = "RISKHUB_KICK_SIGNAL";
				val.paramTokens = new string[1] { user.id.value.ToString() };
				Chat.SendBroadcastChat((ChatMessageBase)(object)val);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Kick-Signal: " + ex.Message));
			}
			Message = HubLoc.Tr("Spieler wird entfernt …");
			((MonoBehaviour)this).StartCoroutine(KickSteps(user, connectionToClient, user.userName));
		}
	}

	private IEnumerator KickSteps(NetworkUser user, NetworkConnection conn, string name)
	{
		yield return (object)new WaitForSecondsRealtime(0.75f);
		if (Object.op_Implicit((Object)(object)user))
		{
			try
			{
				NetworkManagerSystem.singleton.ServerKickClient(conn, (BaseKickReason)new SimpleLocalizedKickReason("KICK_REASON_KICKED", new string[0]));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Kick: " + ex.Message));
			}
		}
		yield return (object)new WaitForSecondsRealtime(1.5f);
		if (Object.op_Implicit((Object)(object)user))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Kick: " + name + " noch da, Server räumt auf."));
			if (avatars.TryGetValue(user, out var avatar))
			{
				DestroyAvatar(avatar);
				avatars.Remove(user);
			}
			try
			{
				NetworkServer.DestroyPlayersForConnection(conn);
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Kick DestroyPlayers: " + ex2.Message));
			}
			yield return (object)new WaitForSecondsRealtime(1f);
			try
			{
				((NetworkManager)NetworkManagerSystem.singleton).OnServerDisconnect(conn);
			}
			catch (Exception ex3)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Kick OnServerDisconnect: " + ex3.Message));
			}
			try
			{
				conn.Disconnect();
			}
			catch
			{
			}
		}
		Message = ((!Object.op_Implicit((Object)(object)user)) ? (name + " " + HubLoc.Tr("wurde aus der Lobby entfernt.")) : HubLoc.Tr("Spieler konnte nicht entfernt werden."));
	}

	private void DestroyAvatar(HubAvatar avatar)
	{
		if (Object.op_Implicit((Object)(object)avatar))
		{
			if (Object.op_Implicit((Object)(object)avatar.User) && (Object)(object)avatar.User.masterObject == (Object)(object)((Component)avatar).gameObject)
			{
				avatar.User.masterObject = null;
			}
			if (Object.op_Implicit((Object)(object)avatar.Master))
			{
				RemoveMinions(avatar.Master);
				avatar.Master.DestroyBody();
			}
			if (NetworkServer.active)
			{
				NetworkServer.Destroy(((Component)avatar).gameObject);
			}
		}
	}

	private void ServerCleanup()
	{
		HubTestItems.CleanupAll();
		((BaseUnityPlugin)this).Logger.LogDebug((object)"RiskHub server cleanup");
		foreach (KeyValuePair<NetworkUser, HubAvatar> avatar in avatars)
		{
			DestroyAvatar(avatar.Value);
		}
		avatars.Clear();
		if (Object.op_Implicit((Object)(object)room))
		{
			room.DestroyDummy();
		}
		HubServices.End();
	}

	private void Teardown()
	{
		if (Object.op_Implicit((Object)(object)room))
		{
			PauseManager.IsAbleToPause = previousPauseAbility;
		}
		if (Object.op_Implicit((Object)(object)hubVotes))
		{
			hubVotes.canRevokeVote = previousRevoke;
			hubVotes.canChangeVote = previousChange;
			hubVotes = null;
		}
		if (Object.op_Implicit((Object)(object)room) && HubServices.MissionActive)
		{
			HubCapsules.ArrivalSession = true;
		}
		if (NetworkServer.active)
		{
			ServerCleanup();
		}
		HubServices.End();
		if (Object.op_Implicit((Object)(object)panels))
		{
			panels.Close();
			Object.Destroy((Object)(object)panels);
		}
		if (Object.op_Implicit((Object)(object)camera))
		{
			Object.Destroy((Object)(object)((Component)camera).gameObject);
		}
		foreach (KeyValuePair<GameObject, bool> item in oldUi)
		{
			if (Object.op_Implicit((Object)(object)item.Key) && !Enabled.Value && Object.op_Implicit((Object)(object)PreGameController.instance) && !departing && !HubServices.MissionActive)
			{
				item.Key.SetActive(item.Value);
			}
		}
		oldUi.Clear();
		foreach (KeyValuePair<Camera, bool> oldCamera in oldCameras)
		{
			if (Object.op_Implicit((Object)(object)oldCamera.Key))
			{
				((Behaviour)oldCamera.Key).enabled = oldCamera.Value;
			}
		}
		oldCameras.Clear();
		if (Object.op_Implicit((Object)(object)room))
		{
			room.Clear();
			Object.Destroy((Object)(object)room);
		}
		room = null;
		panels = null;
		camera = null;
		lobby = null;
		initialized = false;
		departing = false;
	}

	public static object Get(object obj, string name)
	{
		if (obj == null)
		{
			return null;
		}
		Type type = obj.GetType();
		while (type != null)
		{
			FieldInfo field = type.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null)
			{
				return field.GetValue(obj);
			}
			PropertyInfo property = type.GetProperty(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null)
			{
				return property.GetValue(obj, null);
			}
			type = type.BaseType;
		}
		return null;
	}

	private void RunStarted(Run run)
	{
		if (Enabled.Value)
		{
			HubCapsules.ArrivalSession = true;
		}
		if (queueDocument != null)
		{
			((MonoBehaviour)this).StartCoroutine(RestoreQueue());
		}
	}

	private IEnumerator RestoreQueue()
	{
		yield return null;
		queueDocument = null;
	}

	private static IEnumerable<CodeInstruction> SpawnPatch(IEnumerable<CodeInstruction> codes)
	{
		MethodInfo native = AccessTools.Method(typeof(Run), "OnServerCharacterBodySpawned", (Type[])null, (Type[])null);
		foreach (CodeInstruction code in codes)
		{
			if (CodeInstructionExtensions.Calls(code, native))
			{
				code.opcode = OpCodes.Call;
				code.operand = AccessTools.Method(typeof(Plugin), "Spawned", (Type[])null, (Type[])null);
			}
			yield return code;
		}
	}

	private static void Spawned(Run run, CharacterBody body)
	{
		if (Active)
		{
			Object.DontDestroyOnLoad((Object)(object)((Component)body).gameObject);
			HubServices.Track(((Component)body).gameObject);
			if (Object.op_Implicit((Object)(object)body.master))
			{
				HubServices.Track(((Component)body.master).gameObject);
			}
		}
		if (HubServices.MissionActive)
		{
			run.OnServerCharacterBodySpawned(body);
		}
	}

	[HarmonyPatch(typeof(CharacterSelectController), "ClientSetReady")]
	[HarmonyPrefix]
	private static bool ReadyFromStation()
	{
		return !Active;
	}

	[HarmonyPatch(typeof(PreGameController), "StartLaunch")]
	[HarmonyPrefix]
	private static void Launch()
	{
		if (Active)
		{
			((Component)Instance).GetComponent<HubLaunchPlatform>().BeginLaunch();
		}
	}

	[HarmonyPatch(typeof(PreGameController), "StartRun")]
	[HarmonyPrefix]
	private static bool BeforeRun()
	{
		if (Active && NetworkServer.active)
		{
			if (!((Component)Instance).GetComponent<HubLaunchPlatform>().AllowStartRun())
			{
				return false;
			}
			Instance.queueDocument = null;
			Instance.departing = true;
			HubCapsules.ArrivalSession = true;
			Instance.ServerCleanup();
		}
		return true;
	}

	[HarmonyPatch(typeof(BaseAchievement), "Grant")]
	[HarmonyPrefix]
	private static bool NoPracticeAchievements()
	{
		return !Active;
	}

	[HarmonyPatch(typeof(BaseServerAchievement), "Grant")]
	[HarmonyPrefix]
	private static bool NoPracticeServerAchievements()
	{
		return !Active;
	}

	[HarmonyPatch(typeof(CharacterMaster), "StartLifeStopwatch")]
	[HarmonyPrefix]
	private static bool PracticeLifeStart()
	{
		return !Active;
	}

	[HarmonyPatch(typeof(PlayerCharacterMasterController), "CanSendBodyInput")]
	[HarmonyPrefix]
	private static bool TerminalInput(ref bool __result)
	{
		if (Active && Object.op_Implicit((Object)(object)Instance.panels) && Instance.panels.IsOpen)
		{
			__result = false;
			return false;
		}
		return true;
	}
}
public sealed class HubAvatar : MonoBehaviour
{
	public NetworkUser User;

	public CharacterMaster Master;

	public bool Respawning;
}
public enum StationKind
{
	Run,
	Players,
	Survivor,
	Queue,
	Training,
	Pod,
	Menu,
	Hall,
	Items
}
public sealed class Station
{
	public StationKind Kind;

	public Vector3 Position;

	public string Name;

	public Transform Root;

	public Transform Display;

	public int PodIndex = -1;
}
public sealed class HubMonitorPower : MonoBehaviour
{
	private Canvas screen;

	private RectTransform content;

	private Image beam;

	private float amount;

	private float target;

	private bool firstTick;

	public Action OffCompleted;

	public bool IsOn => target > 0f;

	public float Reveal => amount;

	public void Initialize(Canvas canvas, RectTransform panel)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		screen = canvas;
		content = panel;
		content.pivot = new Vector2(0.5f, 0.5f);
		content.anchoredPosition = new Vector2(720f, -405f);
		beam = HubUI.Fill(((Component)canvas).transform, "PowerBeam", 20f, 403f, 1400f, 4f, new Color(0.65f, 0.95f, 1f, 1f));
		((Graphic)beam).raycastTarget = false;
		((Component)beam).gameObject.SetActive(false);
		((Component)content).gameObject.SetActive(false);
		((Behaviour)screen).enabled = false;
		amount = (target = 0f);
		((Behaviour)this).enabled = false;
	}

	public void SetPower(bool on)
	{
		target = (on ? 1 : 0);
		RestartClock();
		if (!on && amount <= 0f)
		{
			Off();
			return;
		}
		((Behaviour)screen).enabled = true;
		((Component)content).gameObject.SetActive(true);
		((Component)beam).transform.SetAsLastSibling();
		((Behaviour)this).enabled = true;
		Apply();
	}

	public void RestartClock()
	{
		firstTick = true;
	}

	private void Apply()
	{
		//IL_003c: 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)
		float num = amount * amount * (3f - 2f * amount);
		((Transform)content).localScale = new Vector3(1f, Mathf.Max(0.002f, num), 1f);
		((Component)beam).gameObject.SetActive(amount < 0.98f);
		((Graphic)beam).color = new Color(0.65f, 0.95f, 1f, Mathf.Clamp01((1f - amount) * 3f));
	}

	private void Update()
	{
		float num = ((!firstTick) ? Mathf.Min(Time.unscaledDeltaTime, 0.05f) : 0f);
		firstTick = false;
		amount = Mathf.MoveTowards(amount, target, num / ((!(target > 0f)) ? 0.2f : 0.28f));
		Apply();
		if (Mathf.Approximately(amount, target))
		{
			((Behaviour)this).enabled = false;
			if (target == 0f)
			{
				Off();
			}
			else
			{
				((Component)beam).gameObject.SetActive(false);
			}
		}
	}

	private void Off()
	{
		amount = 0f;
		((Component)content).gameObject.SetActive(false);
		((Component)beam).gameObject.SetActive(false);
		((Behaviour)screen).enabled = false;
		((Behaviour)this).enabled = false;
		if (OffCompleted != null)
		{
			OffCompleted();
		}
	}
}
public sealed class HubLobbyScroll : MonoBehaviour
{
	private RectTransform content;

	private RectTransform viewport;

	private float pause = 2f;

	private bool bottom;

	public void Initialize(RectTransform list, RectTransform mask)
	{
		//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_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		content = list;
		viewport = mask;
		pause = 2f;
		bottom = false;
		Rect rect = content.rect;
		float height = ((Rect)(ref rect)).height;
		Rect rect2 = viewport.rect;
		((Behaviour)this).enabled = height > ((Rect)(ref rect2)).height + 0.5f;
	}

	public void Advance(float delta)
	{
		//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_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)content) || !Object.op_Implicit((Object)(object)viewport))
		{
			return;
		}
		Rect rect = content.rect;
		float height = ((Rect)(ref rect)).height;
		Rect rect2 = viewport.rect;
		float num = Mathf.Max(0f, height - ((Rect)(ref rect2)).height);
		if (num <= 0.5f)
		{
			return;
		}
		if (pause > 0f)
		{
			pause = Mathf.Max(0f, pause - delta);
			return;
		}
		if (bottom)
		{
			content.anchoredPosition = new Vector2(0f, 0f);
			bottom = false;
			pause = 2f;
			return;
		}
		float num2 = Mathf.Min(num, content.anchoredPosition.y + delta * 18f);
		content.anchoredPosition = new Vector2(0f, num2);
		if (num2 >= num)
		{
			bottom = true;
			pause = 1f;
		}
	}

	private void Update()
	{
		Advance(Mathf.Min(Time.unscaledDeltaTime, 0.1f));
	}
}
[Serializable]
public sealed class HubRunRecord
{
	public string Id;

	public string Survivor;

	public string Difficulty;

	public string Mode;

	public string Artifacts;

	public int Stages;

	public float Seconds;

	public bool Won;
}
[Serializable]
public sealed class HubRunArchive
{
	public List<HubRunRecord> Runs = new List<HubRunRecord>();
}
[Serializable]
public sealed class HubHallPlayer
{
	public string Name;

	public List<HubRunRecord> Runs = new List<HubRunRecord>();
}
[Serializable]
public sealed class HubHallSnapshot
{
	public List<HubHallPlayer> Players = new List<HubHallPlayer>();
}
public sealed class HubHallPacket : MessageBase
{
	public NetworkInstanceId User;

	public string Json;

	public override void Serialize(NetworkWriter writer)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		writer.Write(User);
		writer.Write(Json ?? string.Empty);
	}

	public override void Deserialize(NetworkReader reader)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		User = reader.ReadNetworkId();
		Json = reader.ReadString();
	}
}
public sealed class HubHallOfFame : MonoBehaviour
{
	public const short SubmitId = 28492;

	public const short SnapshotId = 28493;

	private readonly Dictionary<uint, List<HubRunRecord>> submitted = new Dictionary<uint, List<HubRunRecord>>();

	private readonly Dictionary<string, HubRunArchive> archives = new Dictionary<string, HubRunArchive>();

	private readonly List<TMP_Text> labels = new List<TMP_Text>();

	private Canvas board;

	private Transform boardContent;

	private HubHallSnapshot cached = new HubHallSnapshot();

	private NetworkClient client;

	private float scan;

	private string lastOwn = string.Empty;

	private string lastSnapshot = string.Empty;

	private string pending = string.Empty;

	private NetworkInstanceId lastUser;

	private PreGameController session;

	private bool serverRegistered;

	public Canvas Board => board;

	public RectTransform Panel { get; private set; }

	public HubMonitorPower Power { get; private set; }

	public int Revision { get; private set; }

	public bool Visible => Object.op_Implicit((Object)(object)board) && ((Behaviour)board).enabled;

	public static List<HubRunRecord> Best(List<HubRunRecord> runs)
	{
		List<HubRunRecord> list = new List<HubRunRecord>(runs ?? new List<HubRunRecord>());
		list.RemoveAll((HubRunRecord r) => r == null);
		list.Sort(delegate(HubRunRecord a, HubRunRecord b)
		{
			int num = b.Stages.CompareTo(a.Stages);
			if (num == 0)
			{
				num = b.Won.CompareTo(a.Won);
			}
			if (num == 0)
			{
				num = a.Seconds.CompareTo(b.Seconds);
			}
			return num;
		});
		if (list.Count > 3)
		{
			list.RemoveRange(3, list.Count - 3);
		}
		return list;
	}

	private static string Clean(string value)
	{
		return (value ?? string.Empty).Replace("<", "‹").Replace(">", "›");
	}

	private static string PathFor(string key)
	{
		char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
		foreach (char oldChar in invalidFileNameChars)
		{
			key = key.Replace(oldChar, '_');
		}
		return Path.Combine(Paths.ConfigPath, "RiskHubRuns", key + ".json");
	}

	private HubRunArchive Archive(string key)
	{
		if (archives.TryGetValue(key, out var value))
		{
			return value;
		}
		try
		{
			string path = PathFor(key);
			value = ((!File.Exists(path)) ? null : JsonUtility.FromJson<HubRunArchive>(File.ReadAllText(path)));
		}
		catch (Exception ex)
		{
			Plugin.Instance.LoggerForHall("Runarchiv konnte nicht gelesen werden: " + ex.Message);
			value = null;
		}
		if (value == null)
		{
			value = new HubRunArchive();
		}
		if (value.Runs == null)
		{
			value.Runs = new List<HubRunRecord>();
		}
		archives[key] = value;
		return value;
	}

	private void Awake()
	{
		Run.onClientGameOverGlobal += Record;
	}

	private void OnDestroy()
	{
		Run.onClientGameOverGlobal -= Record;
	}

	private void Record(Run run, RunReport report)
	{
		//IL_00be: 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_00fd: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)run) || !HubServices.MissionActive || report == null)
		{
			return;
		}
		foreach (LocalUser readOnlyLocalUsers in LocalUserManager.readOnlyLocalUsersList)
		{
			if (readOnlyLocalUsers.userProfile == null)
			{
				continue;
			}
			string fileName = readOnlyLocalUsers.userProfile.fileName;
			if (string.IsNullOrEmpty(fileName))
			{
				continue;
			}
			PlayerInfo val = report.FindPlayerInfo(readOnlyLocalUsers);
			if (val == null)
			{
				continue;
			}
			HubRunArchive hubRunArchive = Archive(fileName);
			string id = report.runGuid.ToString();
			if (hubRunArchive.Runs.Exists((HubRunRecord r) => r.Id == id))
			{
				continue;
			}
			GameObject bodyPrefab = BodyCatalog.GetBodyPrefab(val.bodyIndex);
			CharacterBody val2 = ((!Object.op_Implicit((Object)(object)bodyPrefab)) ? null : bodyPrefab.GetComponent<CharacterBody>());
			string difficulty = ((object)run.selectedDifficulty/*cast due to .constrained prefix*/).ToString();
			DifficultyDef difficultyDef = DifficultyCatalog.GetDifficultyDef(run.selectedDifficulty);
			if (difficultyDef != null)
			{
				difficulty = Language.GetString(difficultyDef.nameToken);
			}
			string text = string.Empty;
			for (int num = 0; num < ArtifactCatalog.artifactCount; num++)
			{
				ArtifactDef artifactDef = ArtifactCatalog.GetArtifactDef((ArtifactIndex)num);
				RuleDef val3 = RuleCatalog.FindRuleDef("Artifacts." + artifactDef.cachedName);
				RuleChoiceDef val4 = ((val3 == null || report.ruleBook == null) ? null : report.ruleBook.GetRuleChoice(val3));
				if (val4 != null && val4.localName == "On")
				{
					if (text.Length > 0)
					{
						text += ", ";
					}
					text += Language.GetString(artifactDef.nameToken);
				}
			}
			hubRunArchive.Runs.Add(new HubRunRecord
			{
				Id = id,
				Survivor = ((!Object.op_Implicit((Object)(object)val2)) ? "Survivor" : Language.GetString(val2.baseNameToken)),
				Difficulty = difficulty,
				Mode = ((Object)run).name.Replace("(Clone)", string.Empty),
				Artifacts = text,
				Stages = run.stageClearCount,
				Seconds = report.runStopwatchValue,
				Won = (Object.op_Implicit((Object)(object)report.gameEnding) && report.gameEnding.isWin)
			});
			if (hubRunArchive.Runs.Count > 200)
			{
				hubRunArchive.Runs.RemoveRange(0, hubRunArchive.Runs.Count - 200);
			}
			try
			{
				string text2 = PathFor(fileName);
				Directory.CreateDirectory(Path.GetDirectoryName(text2));
				string text3 = text2 + ".tmp";
				File.WriteAllText(text3, JsonUtility.ToJson((object)hubRunArchive, true));
				if (File.Exists(text2))
				{
					File.Replace(text3, text2, text2 + ".bak");
				}
				else
				{
					File.Move(text3, text2);
				}
			}
			catch (Exception ex)
			{
				Plugin.Instance.LoggerForHall("Runarchiv konnte nicht gespeichert werden: " + ex.Message);
			}
		}
	}

	public void Attach(Transform room)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Expected O, but got Unknown
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: 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_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		submitted.Clear();
		lastOwn = (lastSnapshot = (pending = string.Empty));
		lastUser = NetworkInstanceId.Invalid;
		session = PreGameController.instance;
		GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
		((Object)val).name = "RiskHubHallOfFameFrame";
		val.transform.SetParent(room, false);
		val.transform.localPosition = new Vector3(5.55f, 5.1f, -15f);
		val.transform.localScale = new Vector3(0.2f, 7.2f, 18f);
		LayerIndex world = LayerIndex.world;
		val.layer = world.intVal;
		Material val2 = new Material(val.GetComponent<Renderer>().sharedMaterial);
		val2.color = Color.black;
		val.GetComponent<Renderer>().sharedMaterial = val2;
		val.AddComponent<HubOwnedMaterial>().Value = val2;
		board = HubUI.WorldCanvas(room, "RiskHubHallOfFame", new Vector3(5.4f, 5.1f, -15f), Quaternion.Euler(0f, 90f, 0f), 17.7f, 6.9f);
		Panel = HubUI.Rect(((Component)board).transform, "ScreenContent", 0f, 0f, 1440f, 810f);
		boardContent = null;
		Power = ((Component)board).gameObject.AddComponent<HubMonitorPower>();
		Power.Initialize(board, Panel);
		Plugin.Instance.room.Stations.Add(new Station
		{
			Kind = StationKind.Hall,
			Name = "HALL OF FAME",
			Position = Plugin.Origin + new Vector3(4.5f, 0f, -15f),
			Root = val.transform,
			Display = ((Component)board).transform
		});
	}

	private void Update()
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Expected O, but got Unknown
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: 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)
		//IL_0281: Unknown result type (might be due to invalid IL or missing references)
		//IL_0286: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		if (!Plugin.Active)
		{
			session = null;
			serverRegistered = false;
			lastOwn = string.Empty;
		}
		else
		{
			if (!Object.op_Implicit((Object)(object)board) || (Object)(object)session != (Object)(object)PreGameController.instance || Time.unscaledTime < scan)
			{
				return;
			}
			scan = Time.unscaledTime + 0.5f;
			Plugin instance = Plugin.Instance;
			if (NetworkServer.active && !serverRegistered)
			{
				NetworkServer.RegisterHandler((short)28492, new NetworkMessageDelegate(ReceiveSubmit));
				serverRegistered = true;
			}
			NetworkManager singleton = NetworkManager.singleton;
			if (Object.op_Implicit((Object)(object)singleton) && singleton.client != null && client != singleton.client)
			{
				client = singleton.client;
				client.RegisterHandler((short)28493, new NetworkMessageDelegate(ReceiveSnapshot));
				lastOwn = string.Empty;
			}
			NetworkUser val = ((instance.User == null) ? null : instance.User.currentNetworkUser);
			if (Object.op_Implicit((Object)(object)val) && client != null && client.isConnected)
			{
				HubRunArchive hubRunArchive = new HubRunArchive();
				hubRunArchive.Runs = Best(Archive(instance.User.userProfile.fileName).Runs);
				HubRunArchive hubRunArchive2 = hubRunArchive;
				string text = JsonUtility.ToJson((object)hubRunArchive2);
				if (text != lastOwn || ((NetworkBehaviour)val).netId != lastUser)
				{
					lastOwn = text;
					lastUser = ((NetworkBehaviour)val).netId;
					if (NetworkServer.active)
					{
						Dictionary<uint, List<HubRunRecord>> dictionary = submitted;
						NetworkInstanceId netId = ((NetworkBehaviour)val).netId;
						dictionary[((NetworkInstanceId)(ref netId)).Value] = hubRunArchive2.Runs;
					}
					else
					{
						client.Send((short)28492, (MessageBase)(object)new HubHallPacket
						{
							User = ((NetworkBehaviour)val).netId,
							Json = text
						});
					}
				}
			}
			if (NetworkServer.active)
			{
				HubHallSnapshot hubHallSnapshot = new HubHallSnapshot();
				foreach (NetworkUser readOnlyInstances in NetworkUser.readOnlyInstancesList)
				{
					if (Object.op_Implicit((Object)(object)readOnlyInstances))
					{
						Dictionary<uint, List<HubRunRecord>> dictionary2 = submitted;
						NetworkInstanceId netId2 = ((NetworkBehaviour)readOnlyInstances).netId;
						dictionary2.TryGetValue(((NetworkInstanceId)(ref netId2)).Value, out var value);
						hubHallSnapshot.Players.Add(new HubHallPlayer
						{
							Name = ((!string.IsNullOrEmpty(readOnlyInstances.userName)) ? readOnlyInstances.userName : ("Spieler " + ((NetworkBehaviour)readOnlyInstances).netId)),
							Runs = Best(value)
						});
					}
				}
				string text2 = JsonUtility.ToJson((object)hubHallSnapshot);
				if (text2 != lastSnapshot)
				{
					lastSnapshot = text2;
					Draw(hubHallSnapshot);
					NetworkServer.SendToAll((short)28493, (MessageBase)(object)new HubHallPacket
					{
						Json = text2
					});
				}
			}
			if (pending.Length > 0)
			{
				string text3 = pending;
				pending = string.Empty;
				if (text3 != lastSnapshot)
				{
					lastSnapshot = text3;
					Draw(JsonUtility.FromJson<HubHallSnapshot>(text3));
				}
			}
		}
	}

	private static void ReceiveSubmit(NetworkMessage message)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkServer.active || !Plugin.Active)
		{
			return;
		}
		HubHallPacket hubHallPacket = message.ReadMessage<HubHallPacket>();
		if (hubHallPacket.Json == null || hubHallPacket.Json.Length > 12000)
		{
			return;
		}
		GameObject val = NetworkServer.FindLocalObject(hubHallPacket.User);
		NetworkUser val2 = ((!Object.op_Implicit((Object)(object)val)) ? null : val.GetComponent<NetworkUser>());
		if (!Object.op_Implicit((Object)(object)val2) || ((NetworkBehaviour)val2).connectionToClient != message.conn)
		{
			return;
		}
		try
		{
			List<HubRunRecord> list = Best(JsonUtility.FromJson<HubRunArchive>(hubHallPacket.Json)?.Runs);
			list.RemoveAll((HubRunRecord r) => r.Stages < 0 || r.Stages > 10000 || float.IsNaN(r.Seconds) || float.IsInfinity(r.Seconds) || r.Seconds < 0f || (r.Survivor ?? string.Empty).Length > 100 || (r.Difficulty ?? string.Empty).Length > 100 || (r.Artifacts ?? string.Empty).Length > 2000);
			HubHallOfFame component = ((Component)Plugin.Instance).GetComponent<HubHallOfFame>();
			Dictionary<uint, List<HubRunRecord>> dictionary = component.submitted;
			NetworkInstanceId netId = ((NetworkBehaviour)val2).netId;
			dictionary[((NetworkInstanceId)(ref netId)).Value] = list;
			component.lastSnapshot = string.Empty;
		}
		catch
		{
		}
	}

	private static void ReceiveSnapshot(NetworkMessage message)
	{
		if (!NetworkServer.active && Plugin.Active)
		{
			HubHallPacket hubHallPacket = message.ReadMessage<HubHallPacket>();
			if (hubHallPacket.Json != null && hubHallPacket.Json.Length <= 28000)
			{
				((Component)Plugin.Instance).GetComponent<HubHallOfFame>().pending = hubHallPacket.Json;
			}
		}
	}

	public void ClearDisplay()
	{
		if (Object.op_Implicit((Object)(object)Panel))
		{
			HubUI.Clear((Transform)(object)Panel);
		}
		boardContent = null;
	}

	public void RefreshDisplay()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)Panel))
		{
			ClearDisplay();
			HubUI.Fill((Transform)(object)Panel, "Background", 0f, 0f, 1440f, 810f, HubUI.Back);
			HubUI.Text((Transform)(object)Panel, "Title", "HALL OF FAME", 32f, 12f, 1376f, 72f, 48f, HubUI.Gold, (TextAlignmentOptions)257);
			HubUI.Text((Transform)(object)Panel, "Ranking", "PERSÖNLICHE TOP 3  ·  STUFEN → SIEG → ZEIT", 32f, 90f, 1376f, 40f, 23f, HubUI.Muted, (TextAlignmentOptions)257);
			boardContent = (Transform)(object)HubUI.Rect((Transform)(object)Panel, "Records", 28f, 160f, 1384f, 620f);
			RenderRecords(cached);
		}
	}

	private void Draw(HubHallSnapshot data)
	{
		cached = data;
		if (Object.op_Implicit((Object)(object)Power) && Power.IsOn)
		{
			if (Object.op_Implicit((Object)(object)boardContent))
			{
				RenderRecords(data);
			}
			else
			{
				RefreshDisplay();
			}
		}
	}

	private void RenderRecords(HubHallSnapshot data)
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)boardContent) || data == null || data.Players == null)
		{
			return;
		}
		HubUI.Clear(boardContent);
		labels.Clear();
		Revision++;
		int num = Math.Min(8, data.Players.Count);
		if (num == 0)
		{
			HubUI.Text(boardContent, "Empty", "WARTE AUF SPIELER …", 20f, 20f, 1300f, 80f, 32f, HubUI.Muted, (TextAlignmentOptions)257);
			return;
		}
		int num2 = ((num > 2) ? 4 : num);
		for (int i = 0; i < num; i++)
		{
			HubHallPlayer hubHallPlayer = data.Players[i];
			float num3 = 1360f / (float)num2;
			float num4 = (float)(i % num2) * num3;
			float num5 = i / num2 * 306;
			HubUI.Text(boardContent, "Player" + i, Clean(hubHallPlayer.Name), num4 + 10f, num5, num3 - 20f, 58f, 31f, HubUI.Gold, (TextAlignmentOptions)257);
			string text = string.Empty;
			List<HubRunRecord> list = Best(hubHallPlayer.Runs);
			for (int j = 0; j < list.Count; j++)
			{
				HubRunRecord hubRunRecord = list[j];
				string text2 = text;
				text = text2 + (j + 1) + ". " + Clean(hubRunRecord.Survivor) + "\n" + Clean(hubRunRecord.Difficulty) + " · " + hubRunRecord.Stages + " Stufen\n" + TimeSpan.FromSeconds(Math.Min(hubRunRecord.Seconds, 31536000f)).ToString("hh\\:mm\\:ss") + " · " + ((!hubRunRecord.Won) ? "BEENDET" : "SIEG") + "\n\n";
			}
			if (text.Length == 0)
			{
				text = "Noch kein Run gespeichert.";
			}
			HubUI.Text(boardContent, "Runs" + i, text, num4 + 10f, num5 + 62f, num3 - 20f, 238f, (num > 2) ? 20 : 26, HubUI.White, (TextAlignmentOptions)257);
		}
	}
}
public sealed class HubOwnedMaterial : MonoBehaviour
{
	public Material Value;

	private void OnDestroy()
	{
		if (Object.op_Implicit((Object)(object)Value))
		{
			Object.Destroy((Object)(object)Value);
		}
	}
}
public static class HubLayout
{
	public const float TrainingFront = -2f;

	public const float Left = -32f;

	public const float Right = 6f;

	public const float CenterX = -13f;

	public const float Width = 38f;

	public const float TrainingCenterZ = 14f;

	public static readonly Vector3 SpawnPoint = new Vector3(-19f, 1f, -15f);

	public static readonly Vector3 PlatformOffset = new Vector3(-19f, 0f, -1f);

	public static readonly Vector3 WaitingCenter = new Vector3(-19f, 0f, -12f);

	public static Vector3 Position(StationKind kind)
	{
		//IL_003e: 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_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: 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)
		return (Vector3)(kind switch
		{
			StationKind.Run => new Vector3(-22f, 0f, -3f), 
			StationKind.Survivor => new Vector3(-16f, 0f, -3f), 
			StationKind.Queue => new Vector3(4.8f, 0f, -26.5f), 
			StationKind.Items => new Vector3(-28.15f, 0f, 27.85f), 
			StationKind.Players => new Vector3(-10f, 0f, -3f), 
			_ => new Vector3(-30.2f, 0f, 25.8f), 
		});
	}
}
[HarmonyPatch]
public static class HubLateLobbyUI
{
	private static IEnumerable<MethodBase> TargetMethods()
	{
		string[] array = new string[3] { "Awake", "Start", "OnEnable" };
		foreach (string name in array)
		{
			MethodInfo method = typeof(CharacterSelectController).GetMethod(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			if (method != null && method.GetMethodBody() != null)
			{
				yield return method;
			}
		}
	}

	private static void Postfix()
	{
		if (Plugin.Active)
		{
			Plugin.Instance.RediscoverLobby();
		}
	}
}
public static class HubVoteWriteDedup
{
	private static Type pluginType;

	private static FieldInfo votesField;

	private static FieldInfo valueField;

	private static readonly Dictionary<LocalUser, byte[]> previous = new Dictionary<LocalUser, byte[]>();

	public static int Skipped;

	public static int Allowed;

	public static void Install(Harmony harmony)
	{
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		pluginType = AccessTools.TypeByName("LobbyVotesSaveRedux.Plugin");
		if (!(pluginType == null))
		{
			MethodInfo methodInfo = AccessTools.Method(pluginType, "StoreVotes", (Type[])null, (Type[])null);
			if (!(methodInfo == null))
			{
				MethodInfo methodInfo2 = methodInfo;
				HarmonyMethod val = new HarmonyMethod(typeof(HubVoteWriteDedup), "AfterNative", (Type[])null);
				harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}
	}

	private static IEnumerable<CodeInstruction> AfterNative(IEnumerable<CodeInstruction> original, ILGenerator generator)
	{
		Label end = generator.DefineLabel();
		bool inserted = false;
		foreach (CodeInstruction instruction in original)
		{
			yield return instruction;
			MethodInfo method = instruction.operand as MethodInfo;
			if (!inserted && method != null && method.Name == "Invoke" && method.DeclaringType.Name == "orig_OnVotesUpdated")
			{
				inserted = true;
				yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(HubVoteWriteDedup), "ShouldWrite", (Type[])null, (Type[])null));
				yield return new CodeInstruction(OpCodes.Brfalse, (object)end);
			}
		}
		CodeInstruction ret = new CodeInstruction(OpCodes.Ret, (object)null);
		ret.labels.Add(end);
		yield return ret;
	}

	public static bool ShouldWrite()
	{
		if (!Plugin.Active)
		{
			previous.Clear();
			return true;
		}
		try
		{
			if (votesField == null)
			{
				votesField = AccessTools.Field(pluginType, "VotesCacheField").GetValue(null) as FieldInfo;
			}
			if (valueField == null)
			{
				valueField = AccessTools.Field(pluginType, "InternalValueField").GetValue(null) as FieldInfo;
			}
			IDictionary dictionary = ((!(votesField != null)) ? null : (votesField.GetValue(null) as IDictionary));
			if (dictionary == null || valueField == null)
			{
				return true;
			}
			bool flag = false;
			foreach (DictionaryEntry item in dictionary)
			{
				object key = item.Key;
				LocalUser val = (LocalUser)((key is LocalUser) ? key : null);
				Array array = item.Value as Array;
				if (val == null || array == null)
				{
					continue;
				}
				if (!previous.TryGetValue(val, out var value) || value.Length != array.Length)
				{
					value = new byte[array.Length];
					previous[val] = value;
					flag = true;
				}
				for (int i = 0; i < array.Length; i++)
				{
					byte b = (byte)valueField.GetValue(array.GetValue(i));
					if (value[i] != b)
					{
						value[i] = b;
						flag = true;
					}
				}
			}
			if (flag)
			{
				Allowed++;
			}
			else
			{
				Skipped++;
			}
			return flag;
		}
		catch
		{
			return true;
		}
	}
}
public sealed class HubWorld : MonoBehaviour
{
	private GameObject root;

	private bool buildingPlatform;

	private readonly List<Mesh> combinedMeshes = new List<Mesh>();

	private readonly List<Material> materials = new List<Material>();

	public readonly List<Station> Stations = new List<Station>();

	private Material metal;

	private Material dark;

	private Material light;

	private Material glass;

	private Material platformGlow;

	private Material screenOff;

	private bool platformReady;

	private TMP_Text platformStatus;

	public const float HalfWidth = 19f;

	public const float HalfDepth = 30f;

	public const float Height = 18f;

	public static readonly Vector3 PlatformCenter = new Vector3(-19f, 0.22f, -23f);

	public float LastHit;

	public int Hits;

	public bool TrainingImmortal = true;

	private Color oldAmbient;

	private float oldIntensity;

	private bool oldFog;

	private int oldScene;

	private AmbientMode oldAmbientMode;

	public bool PlatformReady => platformReady;

	public HubTraining Training { get; private set; }

	public CharacterMaster Dummy => (!Object.op_Implicit((Object)(object)Training)) ? null : Training.First;

	public bool DummyInitialized => Object.op_Implicit((Object)(object)Training) && Training.Initialized;

	public float RespawnRemaining => (!Object.op_Implicit((Object)(object)Training)) ? 0f : Training.RespawnRemaining;

	public void Build()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: 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_0134: 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_017a: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: 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_01ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02db: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_0361: Unknown result type (might be due to invalid IL or missing references)
		//IL_0375: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0400: Unknown result type (might be due to invalid IL or missing references)
		//IL_0414: Unknown result type (might be due to invalid IL or missing references)
		//IL_0470: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_056c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0580: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_0605: Unknown result type (might be due to invalid IL or missing references)
		//IL_0619: Unknown result type (might be due to invalid IL or missing references)
		//IL_063c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0650: Unknown result type (might be due to invalid IL or missing references)
		//IL_0687: Unknown result type (might be due to invalid IL or missing references)
		//IL_069b: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_06fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_070f: Unknown result type (might be due to invalid IL or missing references)
		//IL_075a: Unknown result type (might be due to invalid IL or missing references)
		//IL_076e: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_07de: Unknown result type (might be due to invalid IL or missing references)
		//IL_0815: Unknown result type (might be due to invalid IL or missing references)
		//IL_0829: Unknown result type (might be due to invalid IL or missing references)
		//IL_084f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0863: Unknown result type (might be due to invalid IL or missing references)
		//IL_0893: Unknown result type (might be due to invalid IL or missing references)
		//IL_0898: Unknown result type (might be due to invalid IL or missing references)
		//IL_089d: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_08e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0928: Unknown result type (might be due to invalid IL or missing references)
		//IL_0953: Unknown result type (might be due to invalid IL or missing references)
		//IL_095a: Expected O, but got Unknown
		//IL_0988: Unknown result type (might be due to invalid IL or missing references)
		//IL_09c0: Unknown result type (might be due to invalid IL or missing references)
		root = new GameObject("RiskHubCommandCenter");
		root.transform.SetParent(((Component)Plugin.Instance).transform, false);
		root.transform.position = Plugin.Origin;
		Scene activeScene = SceneManager.GetActiveScene();
		oldScene = ((Scene)(ref activeScene)).handle;
		oldAmbientMode = RenderSettings.ambientMode;
		oldAmbient = RenderSettings.ambientLight;
		oldIntensity = RenderSettings.ambientIntensity;
		oldFog = RenderSettings.fog;
		RenderSettings.ambientMode = (AmbientMode)3;
		RenderSettings.ambientLight = new Color(0.45f, 0.55f, 0.65f);
		RenderSettings.ambientIntensity = 0.8f;
		RenderSettings.fog = false;
		screenOff = Material(Color.black, emissive: false);
		metal = Material(new Color(0.1f, 0.15f, 0.2f), emissive: false);
		dark = Material(new Color(0.025f, 0.045f, 0.065f), emissive: false);
		light = Material(new Color(0.1f, 0.8f, 1f), emissive: true);
		glass = Material(new Color(0.03f, 0.09f, 0.14f), emissive: false);
		platformGlow = Material(new Color(0.1f, 0.8f, 1f), emissive: true);
		Box("Deck", new Vector3(-13f, -0.5f, 0f), new Vector3(38f, 1f, 60f), metal);
		Box("Ceiling", new Vector3(-13f, 18.25f, 0f), new Vector3(38f, 0.5f, 60f), dark);
		Box("PortWall", new Vector3(-32f, 9f, 0f), new Vector3(0.5f, 18f, 60f), metal);
		Box("StarboardWall", new Vector3(6f, 9f, 0f), new Vector3(0.5f, 18f, 60f), metal);
		Box("AftWall", new Vector3(-13f, 9f, -30f), new Vector3(38f, 18f, 0.5f), metal);
		Box("ForwardWall", new Vector3(-13f, 9f, 30f), new Vector3(38f, 18f, 0.5f), metal);
		for (int i = -30; (float)i < 6f; i += 6)
		{
			Box("DeckSeam", new Vector3((float)i, 0.012f, 0f), new Vector3(0.025f, 0.01f, 59f), dark);
			Box("CeilingBeam", new Vector3((float)i, 17.7f, 0f), new Vector3(0.18f, 0.5f, 60f), metal);
		}
		for (int j = -24; j <= 24; j += 6)
		{
			Box("DeckSeam", new Vector3(-13f, 0.013f, (float)j), new Vector3(37f, 0.01f, 0.025f), dark);
		}
		float[] array = new float[2] { -31.7f, 5.7f };
		foreach (float num in array)
		{
			Box("WallLight", new Vector3(num, 1.1f, 0f), new Vector3(0.03f, 0.05f, 59f), light);
			Box("WallLight", new Vector3(num, 12f, 0f), new Vector3(0.03f, 0.06f, 59f), light);
		}
		float[] array2 = new float[2] { -24f, -14f };
		foreach (float num2 in array2)
		{
			Box("WalkwayLight", new Vector3(num2, 0.025f, -7f), new Vector3(0.05f, 0.02f, 32f), light);
		}
		AddStation(StationKind.Run, "MISSIONSKONTROLLE", HubLayout.Position(StationKind.Run));
		AddStation(StationKind.Survivor, "AUSRÜSTUNG", HubLayout.Position(StationKind.Survivor));
		AddStation(StationKind.Queue, "COMMAND QUEUE", HubLayout.Position(StationKind.Queue));
		AddStation(StationKind.Training, "TRAININGSBEREICH", HubLayout.Position(StationKind.Training));
		AddStation(StationKind.Items, "TESTINVENTAR", HubLayout.Position(StationKind.Items));
		HubLocalUnlocks.BuildButton(Stations.Find((Station s) => s.Kind == StationKind.Queue));
		BuildTrainingRoom();
		Training = ((Component)this).gameObject.AddComponent<HubTraining>();
		Training.Initialize(this);
		buildingPlatform = true;
		Box("LaunchPlatform", new Vector3(0f, 0.11f, -22f), new Vector3(16f, 0.22f, 10f), dark);
		Box("PlatformBridge", new Vector3(0f, 0.055f, -14.5f), new Vector3(8f, 0.11f, 5f), metal);
		float[] array3 = new float[2] { -8f, 8f };
		foreach (float num4 in array3)
		{
			Box("PlatformSideRail", new Vector3(num4, 0.85f, -22f), new Vector3(0.14f, 1.3f, 10f), metal);
			Box("PlatformRim", new Vector3(num4, 0.25f, -22f), new Vector3(0.12f, 0.06f, 10f), platformGlow);
		}
		Box("PlatformBackRail", new Vector3(0f, 0.85f, -27f), new Vector3(16f, 1.3f, 0.14f), metal);
		Box("PlatformRim", new Vector3(0f, 0.25f, -27f), new Vector3(16f, 0.06f, 0.12f), platformGlow);
		Box("PlatformRim", new Vector3(0f, 0.25f, -17f), new Vector3(16f, 0.06f, 0.12f), platformGlow);
		float[] array4 = new float[2] { -4f, 4f };
		foreach (float num6 in array4)
		{
			Box("BridgeGuide", new Vector3(num6, 0.15f, -14.5f), new Vector3(0.05f, 0.035f, 5f), light);
		}
		float[] array5 = new float[2] { -9f, 9f };
		foreach (float num8 in array5)
		{
			Box("LaunchArch", new Vector3(num8, 2.5f, -27.3f), new Vector3(0.5f, 5f, 0.6f), metal);
		}
		Box("LaunchArchHeader", new Vector3(0f, 5f, -27.3f), new Vector3(18.5f, 1.2f, 0.6f), dark);
		Box("ArchLight", new Vector3(0f, 5.65f, -27.3f), new Vector3(18.5f, 0.06f, 0.6f), light);
		Canvas val = HubUI.WorldCanvas(root.transform, "LaunchPlatformBanner", new Vector3(0f, 5f, -26.95f) + HubLayout.PlatformOffset, Quaternion.Euler(0f, 180f, 0f), 16f, 1f);
		((Component)val).GetComponent<RectTransform>().sizeDelta = new Vector2(1440f, 100f);
		((Component)val).transform.localScale = Vector3.one * (1f / 90f);
		platformStatus = (TMP_Text)(object)HubUI.Text(((Component)val).transform, "PlatformStatus", "STARTPLATTFORM — ZUM START SAMMELN", 0f, 0f, 1440f, 100f, 42f, HubUI.White, (TextAlignmentOptions)514);
		buildingPlatform = false;
		BuildLobbyBoard();
		GameObject val2 = new GameObject("RiskHubSunlight");
		val2.transform.SetParent(root.transform, false);
		val2.transform.rotation = Quaternion.Euler(55f, -25f, 0f);
		Light val3 = val2.AddComponent<Light>();
		val3.type = (LightType)1;
		val3.intensity = 1.2f;
		val3.color = new Color(0.75f, 0.85f, 1f);
		val3.shadows = (LightShadows)0;
		CombineStaticGeometry();
		HubExitDoor.Build(root.transform, metal, dark, light);
	}

	private void BuildLobbyBoard()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		Box("LobbyWallFrame", new Vector3(5.55f, 5.1f, -15f), new Vector3(0.2f, 7.2f, 18f), dark);
		Transform transform = new GameObject("LobbyWallDisplay").transform;
		transform.SetParent(root.transform, false);
		transform.localPosition = new Vector3(5.4f, 5.1f, -15f);
		transform.localRotation = Quaternion.Euler(0f, 90f, 0f);
		Stations.Add(new Station
		{
			Kind = StationKind.Players,
			Name = "LOBBY",
			Position = Plugin.Origin + new Vector3(3.5f, 0f, -15f),
			Root = transform,
			Display = transform
		});
	}

	private void BuildTrainingRoom()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_002c: 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_0094: 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_00c9: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_020e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0222: Unknown result type (might be due to invalid IL or missing references)
		//IL_0259: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Expected O, but got Unknown
		//IL_0318: Unknown result type (might be due to invalid IL or missing references)
		//IL_0365: Unknown result type (might be due to invalid IL or missing references)
		//IL_0376: Unknown result type (might be due to invalid IL or missing references)
		//IL_0398: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0416: Unknown result type (might be due to invalid IL or missing references)
		//IL_041b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0442: Unknown result type (might be due to invalid IL or missing references)
		//IL_0453: Unknown result type (might be due to invalid IL or missing references)
		//IL_045d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0491: Unknown result type (might be due to invalid IL or missing references)
		Material val = new Material(Graphic.defaultGraphicMaterial);
		materials.Add(val);
		val.color = new Color(0.52f, 0.54f, 0.56f, 1f);
		val.mainTexture = (Texture)(object)Texture2D.whiteTexture;
		val.SetInt("unity_GUIZTestMode", 4);
		val.renderQueue = 2450;
		((Object)val).name = "TrainingLightGrey";
		Material material = Material(new Color(0.22f, 0.27f, 0.32f), emissive: false);
		Box("TrainingFloor", new Vector3(-13f, 0.015f, 14f), new Vector3(37.5f, 0.06f, 31.5f), val);
		Box("TrainingBackWall", new Vector3(-13f, 9f, 29.4f), new Vector3(37.5f, 18f, 0.5f), material);
		Box("TrainingRightWall", new Vector3(5.6f, 9f, 13.75f), new Vector3(0.3f, 18f, 31.5f), material);
		Box("TrainingLeftWall", new Vector3(-31.6f, 9f, 13.75f), new Vector3(0.3f, 18f, 31.5f), material);
		float num = 5.8f;
		float num2 = -23.5f;
		float num3 = (num2 + num) * 0.5f;
		float num4 = num - num2;
		Box("TrainingPartitionBase", new Vector3(num3, 0.55f, -2f), new Vector3(num4, 1.1f, 0.25f), metal);
		Box("TrainingPartitionHeader", new Vector3(num3, 17.5f, -2f), new Vector3(num4, 1f, 0.3f), metal);
		float[] array = new float[3] { num2, num3, num };
		foreach (float num5 in array)
		{
			Box("TrainingGlassFrame", new Vector3(num5, 9f, -2f), new Vector3(0.16f, 16f, 0.3f), metal);
		}
		Box("TrainingEntryUpperWall", new Vector3(-27.75f, 11.25f, -2f), new Vector3(8.5f, 13.5f, 0.3f), material);
		float[] array2 = new float[2] { -31.7f, -23.5f };
		foreach (float num6 in array2)
		{
			Box("TrainingEntryJamb", new Vector3(num6, 2.25f, -2f), new Vector3(0.3f, 4.5f, 0.3f), metal);
		}
		Material val2 = new Material(Graphic.defaultGraphicMaterial);
		materials.Add(val2);
		val2.color = new Color(0.42f, 0.7f, 0.55f, 0.06f);
		val2.mainTexture = (Texture)(object)Texture2D.whiteTexture;
		((Object)val2).name = "TrainingGlassSoftGreen";
		val2.SetInt("unity_GUIZTestMode", 4);
		val2.renderQueue = 3000;
		Box("TrainingGlass", new Vector3(num3, 9.15f, -2f), new Vector3(num4, 16.1f, 0.05f), val2);
		Box("TrainingEntryGuide", new Vector3(-27.6f, 0.08f, -2f), new Vector3(7.8f, 0.04f, 0.12f), light);
		Box("TrainingEntryHeader", new Vector3(-27.6f, 4.2f, -2f), new Vector3(7.8f, 0.6f, 0.3f), dark);
		Canvas val3 = HubUI.WorldCanvas(root.transform, "TrainingEntrySign", new Vector3(-27.6f, 4.2f, -2.2f), Quaternion.identity, 7f, 0.5f);
		((Component)val3).GetComponent<RectTransform>().sizeDelta = new Vector2(1400f, 100f);
		((Component)val3).transform.localScale = Vector3.one * 0.005f;
		HubUI.Text(((Component)val3).transform, "TrainingEntryText", "TRAINING  -  EINGANG", 0f, 0f, 1400f, 100f, 64f, HubUI.White, (TextAlignmentOptions)514);
	}

	public static bool OnPlatform(Vector3 foot)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//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_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = foot - Plugin.Origin - PlatformCenter;
		return Mathf.Abs(val.x) < 7.75f && Mathf.Abs(val.z) < 4.75f && val.y >= -0.1f && val.y <= 0.26f;
	}

	public static bool InsideRoom(Vector3 point)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//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_000b: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = point - Plugin.Origin;
		return val.x > -34f && val.x < 8f && Mathf.Abs(val.z) < 32f && val.y > -8f && val.y < 22f;
	}

	public void SetPlatformState(int ready, int total, bool launching)
	{
		//IL_0059: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		bool flag = launching || (total > 0 && ready == total);
		if (platformReady != flag)
		{
			platformReady = flag;
			Color val = ((!flag) ? new Color(0.1f, 0.8f, 1f) : new Color(0.2f, 1f, 0.35f));
			platformGlow.color = val;
			platformGlow.SetColor("_EmissionColor", val * 1.3f);
		}
		if (Object.op_Implicit((Object)(object)platformStatus))
		{
			string text = ((!launching) ? ("STARTPLATTFORM  ·  " + ready + " / " + total + " BEREIT") : "ALLE BEREIT — START");
			if (platformStatus.text != text)
			{
				platformStatus.text = HubLoc.Tr(text);
			}
			((Graphic)platformStatus).color = (Color)((!flag) ? HubUI.White : new Color(0.6f, 1f, 0.65f));
		}
	}

	private void CombineStaticGeometry()
	{
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0201: Expected O, but got Unknown
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Expected O, but got Unknown
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: 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)
		Dictionary<string, List<CombineInstance>> dictionary = new Dictionary<string, List<CombineInstance>>();
		Dictionary<string, Material> dictionary2 = new Dictionary<string, Material>();
		MeshRenderer[] componentsInChildren = root.GetComponentsInChildren<MeshRenderer>();
		foreach (MeshRenderer val in componentsInChildren)
		{
			MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
			if (!((Renderer)val).enabled || !Object.op_Implicit((Object)(object)component) || !Object.op_Implicit((Object)(object)component.sharedMesh) || ((Renderer)val).sharedMaterials.Length != 1)
			{
				continue;
			}
			((Renderer)val).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)val).receiveShadows = false;
			if (!((Object)(object)((Renderer)val).sharedMaterial == (Object)(object)platformGlow) && ((Renderer)val