Decompiled source of LateJoinPlus v1.2.2

LateJoinPlus.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Timers;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using LateJoinPlus.Client;
using LateJoinPlus.Core;
using LateJoinPlus.Guard;
using LateJoinPlus.Join;
using LateJoinPlus.Lobby;
using LateJoinPlus.MapSync;
using LateJoinPlus.Menu;
using LateJoinPlus.Moderation;
using LateJoinPlus.Patches.Late;
using LateJoinPlus.Settings;
using MenuLib;
using MenuLib.MonoBehaviors;
using MenuLib.Structs;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using Photon.Voice;
using Photon.Voice.PUN;
using Photon.Voice.Unity;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Networking;
using UnityEngine.Profiling;
using UnityEngine.SceneManagement;
using UnityEngine.TextCore;
using UnityEngine.TextCore.LowLevel;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LateJoinPlus
{
	public enum PhoneButton
	{
		Up,
		Down,
		Left,
		Right,
		Ok,
		Action,
		Back
	}
	public static class PhoneApps
	{
		internal sealed class App
		{
			internal string Id;

			internal string Name;

			internal Action<Rect> Icon;

			internal Action<Rect> Draw;

			internal Action Tick;

			internal Func<int> Badge;

			internal Func<bool> Back;

			internal bool Faulted;
		}

		public static class Colors
		{
			public static Color Yellow => Ui.Yellow;

			public static Color Orange => Ui.Orange;

			public static Color Text => Ui.Text;

			public static Color Muted => Ui.Muted;

			public static Color Red => Ui.Red;

			public static Color Green => Ui.Green;
		}

		private static readonly List<App> Registered = new List<App>();

		internal static App[] All => Registered.Where((App a) => !a.Faulted).ToArray();

		public static bool UsingMouse => CallPhone.UsingMouse;

		public static bool IsOpen => CallPhone.IsOpen;

		public static float Scale => Ui.S;

		public static bool EditingText => CallPhone.Texting;

		internal static App Find(string id)
		{
			return Registered.FirstOrDefault((App a) => a.Id == id && !a.Faulted);
		}

		public static void Register(string id, string name, Action<Rect> drawIcon, Action<Rect> draw, Action tick, Func<int> badge = null)
		{
			Register(id, name, drawIcon, draw, tick, badge, null);
		}

		public static void Register(string id, string name, Action<Rect> drawIcon, Action<Rect> draw, Action tick, Func<int> badge, Func<bool> back)
		{
			if (string.IsNullOrWhiteSpace(id))
			{
				throw new ArgumentException("An app needs a unique id.", "id");
			}
			App app = new App
			{
				Id = id,
				Name = (name ?? id),
				Icon = drawIcon,
				Draw = draw,
				Tick = tick,
				Badge = badge,
				Back = back
			};
			int num = Registered.FindIndex((App a) => a.Id == id);
			if (num < 0)
			{
				Registered.Add(app);
			}
			else
			{
				Registered[num] = app;
			}
			CallPhone.RefreshApps();
		}

		public static void Unregister(string id)
		{
			Registered.RemoveAll((App a) => a.Id == id);
			if (CallPhone.PluginId == id && CallPhone.Current == CallPhone.Tab.Plugin)
			{
				GoHome();
			}
			CallPhone.RefreshApps();
		}

		internal static void Invoke(App app, Action callback)
		{
			if (app == null || app.Faulted || callback == null)
			{
				return;
			}
			try
			{
				callback();
			}
			catch (Exception error)
			{
				app.Faulted = true;
				PhoneErrors.Report("Phone app " + app.Id, error);
				CallPhone.RefreshApps();
				if (CallPhone.PluginId == app.Id)
				{
					GoHome();
				}
			}
		}

		public static bool Pressed(PhoneButton button)
		{
			return CallPhone.PluginPressed(button);
		}

		public static bool IsActive(string id)
		{
			if (IsOpen && CallPhone.Current == CallPhone.Tab.Plugin)
			{
				return CallPhone.PluginId == id;
			}
			return false;
		}

		public static void Panel(Rect r, Color fill, Color? rim = null, float radius = 10f, float rimWidth = 1.5f)
		{
			//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)
			Ui.Panel(r, fill, rim, radius, rimWidth);
		}

		public static void Line(Rect r, Color color)
		{
			//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)
			Ui.Line(r, color);
		}

		public static void Image(Rect r, Texture2D tex, float alpha = 1f)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			Ui.Image(r, tex, alpha);
		}

		public static void Label(Rect r, string text, float size, Color color, TextAnchor anchor = (TextAnchor)3, bool bold = false)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			Ui.Label(r, text, size, color, anchor, bold);
		}

		public static void Paragraph(Rect r, string text, float size, Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			Ui.Paragraph(r, text, size, color, (TextAnchor)0);
		}

		public static float ParagraphHeight(string text, float size, float width)
		{
			return Ui.ParagraphHeight(text, size, width);
		}

		public static bool Button(Rect r, string text, Color color, float size = 12f, bool on = false, bool enabled = true, string name = null)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return Ui.Button(r, text, color, size, on, enabled, name);
		}

		public static float Width(string text, float size, bool bold = false)
		{
			return Ui.Width(text, size, bold);
		}

		public static string Fit(string text, float size, float width, bool bold = false)
		{
			return Ui.Fit(text, size, width, bold);
		}

		public static string TextField(Rect r, string name, string text, string placeholder, int max)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return CallPhone.PluginField(r, name, text, placeholder, max);
		}

		public static void FocusTextField(string name)
		{
			CallPhone.PluginFocus(name);
		}

		public static void EndTextEditing()
		{
			CallPhone.PluginFocus(null);
		}

		public static bool TextSubmitted(string name)
		{
			return CallPhone.PluginSubmitted(name);
		}

		public static void Banner(string title, string text)
		{
			CallPhone.Banner(title, text, CallPhone.Tab.Home, 0);
		}

		public static void GoHome()
		{
			CallPhone.GoHome();
		}
	}
	internal static class Parts
	{
		internal const string LobbyGuardGuid = "ricketywrecked.repo.lobbyguard";

		internal const string MapSyncFixGuid = "ricketywrecked.repo.mapsyncfix";

		internal static ConfigEntry<bool> GuardEnabled;

		internal static ConfigEntry<bool> OnlyStaffStart;

		internal static ConfigEntry<bool> MapSyncEnabled;

		private static readonly Dictionary<ConfigEntryBase, Action> Appliers = new Dictionary<ConfigEntryBase, Action>();

		internal static void Bind(ConfigFile cfg)
		{
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Expected O, but got Unknown
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Expected O, but got Unknown
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Expected O, but got Unknown
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Expected O, but got Unknown
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Expected O, but got Unknown
			GuardEnabled = cfg.Bind<bool>("Lobby Guard", "Enabled", true, "Lobby Guard on or off: blocks the known lobby-wrecking cheats (fake kicks, host takeover, voice spam), logs every player's Steam ID, and blocks/bans players on your block list. Applied live.");
			Live(cfg.Bind<bool>("Lobby Guard", "BlockHostHijack", true, "Stay in the lobby when someone forcibly makes themselves host while the real host is still there (the game would send everyone to the main menu). As host: take the host role back and ban them."), delegate(bool v)
			{
				HostHijack.Enabled = v && GuardEnabled.Value;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "BlockNameCopies", true, "Block and, as host, ban a player who joins with the name of your moderator, a protected player, a Steam friend or you, from a different Steam account (look-alike letters count). Also a second copy of a player who's here, when only the one already here was seen before. Applied live."), delegate(bool v)
			{
				NameCopies.Enabled = v && GuardEnabled.Value;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "VoiceGuard", true, "Block voices that try to play through someone else's character, junk voice data (the giant emoji spam), and voice-only intruders who aren't in the game."), delegate(bool v)
			{
				VoiceGuard.Enabled = v && GuardEnabled.Value;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "RevealSteamIds", true, "Lobbies you host publish each player's Steam ID (checked by Photon's Steam login), so fake names and fake Steam IDs can be seen through and logged. LateJoinPlus moderators need this, so it stays on while LateJoinPlus moderation is on. Applies to the next lobby you host."), delegate(bool v)
			{
				PublishIds.Enabled = v && GuardEnabled.Value;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "AutoBan", true, "When you are the host, ban blocked players with the game's own ban (Photon's server removes them; a cheat can't ignore it)."), delegate(bool v)
			{
				LateJoinPlus.Guard.Guard.AutoBan = v;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "AutoAddToBlockList", true, "Add the Steam ID of anyone caught doing something a normal game never does to BlockedSteamIds, so they're blocked and banned on sight next time."), delegate(bool v)
			{
				LateJoinPlus.Guard.Guard.AutoBlockAttackers = v;
			});
			LateJoinPlus.Guard.Guard.BlockedSteamIdsEntry = cfg.Bind<string>("Lobby Guard", "BlockedSteamIds", "", "Steam IDs (17 digits, comma-separated) to add to your Block List. They're moved into the list when the game starts and this is emptied: the list is kept on this PC (LJ+ menu > Block List), not in the mod profile, so sharing a profile code doesn't share it.");
			LateJoinPlus.Guard.Guard.BlockedSteamIdsEntry.SettingChanged += delegate
			{
				LateJoinPlus.Guard.Guard.MoveConfigBlocks();
			};
			Live(cfg.Bind<bool>("Lobby Guard", "EnforceHeuristics", false, "Also block (and as host ban) players caught by the guesswork checks below. Careful: a slow PC that takes over 90 seconds to load can look like a ghost and get banned. Off = those are only logged."), delegate(bool v)
			{
				LateJoinPlus.Guard.Guard.EnforceHeuristics = v;
			});
			Live(cfg.Bind<int>("Lobby Guard", "FloodMessagesPerSecond", 500, new ConfigDescription("A player sending more network messages than this per second is flooding.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(100, 2000), Array.Empty<object>())), delegate(int v)
			{
				Firewall.FloodPerSecond = v;
			});
			Live(cfg.Bind<int>("Lobby Guard", "FloodKilobytesPerSecond", 100, new ConfigDescription("A player sending more data than this (KB a second) for about 3 seconds is flooding. When you host they're banned from this lobby, but not added to your block list. Players normally send about 15 KB a second.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 1000), Array.Empty<object>())), delegate(int v)
			{
				Firewall.FloodKilobytesPerSecond = v;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "ChatSpamGuard", true, "Your game ignores chat from one player past 3 messages a second (faster than anyone types), keeps the truck screen's text to a sensible length instead of letting it grow without limit, shortens chat messages over 300 characters, and ignores face expressions that don't exist. A chat-spam cheat froze whole lobbies this way. Normal chat is unchanged. Applied live."), delegate(bool v)
			{
				ChatSpamGuard.Enabled = v && GuardEnabled.Value;
			});
			Live(cfg.Bind<int>("Lobby Guard", "RpcMessagesPerSecond", 250, new ConfigDescription("Maximum messages per RPC name from one player per second after loading settles. Excess messages are ignored; the host is exempt.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(50, 2000), Array.Empty<object>())), delegate(int v)
			{
				Firewall.RpcPerSecond = v;
			});
			Live(cfg.Bind<int>("Lobby Guard", "OutgoingQueueCommands", 1024, new ConfigDescription("Host outgoing command backlog to watch. Three seconds of growth with a dominant incoming data flood removes that sender from this lobby.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(256, 8192), Array.Empty<object>())), delegate(int v)
			{
				Firewall.OutgoingQueueCommands = v;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "HoldBackModOnlyObjects", true, "When you host, don't spawn objects that only exist in another mod, such as RepoCasino's casino. The game sends anyone without that mod back to the menu while a level loads. Turn this off only if everyone in your lobby has the same mods. Applied live."), delegate(bool v)
			{
				ModOnlyObjects.Enabled = v && GuardEnabled.Value;
			});
			Live(cfg.Bind<int>("Lobby Guard", "GhostSeconds", 90, new ConfigDescription("A player in the lobby this long (while a level is running) without ever getting a character is a ghost.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(30, 300), Array.Empty<object>())), delegate(int v)
			{
				Watch.GhostSeconds = v;
			});
			Live(cfg.Bind<bool>("Lobby Guard", "LockGameTools", false, "In lobbies you host, GameTools switches itself off on everyone else's game (moderators too), as when a host's GameTools has Prohibit Others on. Only when you don't have GameTools yourself: with it, use its own Prohibit Others. Applied live."), delegate(bool v)
			{
				GameToolsLock.Wanted = v && GuardEnabled.Value;
			});
			Live(OnlyStaffStart = cfg.Bind<bool>("Lobby Guard", "OnlyStaffStart", false, "In lobbies you host, only you and moderators you've given Truck & extract can start the truck, press the shop checkout, or press BigFriendlyButton's extraction button (to send or cancel an extraction; also its floor box for players without that mod). Anyone else is refused by your game, so it works on players without mods too (the button says no and they're made to let go). Anyone may still open extraction points. Applied live."), delegate(bool v)
			{
				StartLock.Wanted = v && GuardEnabled.Value;
			});
			Live(GuardEnabled, delegate(bool v)
			{
				LateJoinPlus.Guard.Guard.On = v;
			});
			GuardEnabled.SettingChanged += delegate
			{
				ApplyGuardSwitch(cfg);
			};
			MapSyncEnabled = cfg.Bind<bool>("Map Sync", "Enabled", true, "For players who have LateJoinPlus (or Map Sync Fix): as host, send the exact list of rooms explored so far to anyone joining mid-level; when you join someone else's game mid-level, uncover the rooms their host sends. Players without mods get their map filled in by Late Join > RevealMapForJoiners instead, whatever this is set to. Applied live.");
			Live(MapSyncEnabled, delegate(bool v)
			{
				LateJoinPlus.MapSync.MapSync.MapSyncEnabled = v;
			});
			Live(cfg.Bind<bool>("Map Sync", "RevealAllRoomsWhenHostHasNoMod", false, "When you join mid-level and the host doesn't run LateJoinPlus or Map Sync Fix (so it can't send its explored rooms), uncover every room on your map instead. This also shows rooms nobody has explored yet."), delegate(bool v)
			{
				LateJoinPlus.MapSync.MapSync.RevealAllFallback = v;
			});
			bool num = !LateJoinPlus.Guard.Guard.BlocksSaved;
			LateJoinPlus.Guard.Guard.MoveConfigBlocks();
			if (num)
			{
				ImportOldBlockList();
				LateJoinPlus.Guard.Guard.SaveBlockList();
			}
		}

		private static void ApplyGuardSwitch(ConfigFile cfg)
		{
			foreach (ConfigEntryBase item in from kv in (IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)cfg
				select kv.Value into e
				where e.Definition.Section == "Lobby Guard"
				select e)
			{
				LiveApply(item);
			}
		}

		internal static void RestoreSettings()
		{
			foreach (Action value in Appliers.Values)
			{
				value();
			}
		}

		internal static int CheckRuntimeSwitches(List<string> problems)
		{
			bool value = GuardEnabled.Value;
			(string, bool, bool)[] source = new(string, bool, bool)[5]
			{
				("Hub.Enabled", Hub.Enabled, true),
				("Guard.On", LateJoinPlus.Guard.Guard.On, value),
				("HostHijack.Enabled", HostHijack.Enabled, value && SavedBool("BlockHostHijack")),
				("VoiceGuard.Enabled", VoiceGuard.Enabled, value && SavedBool("VoiceGuard")),
				("PublishIds.Enabled", PublishIds.Enabled, value && SavedBool("RevealSteamIds"))
			};
			foreach (var item3 in source.Where(((string, bool, bool) c) => c.Item2 != c.Item3))
			{
				string item = item3.Item1;
				bool item2 = item3.Item3;
				problems.Add(item + " should be " + item2);
			}
			return source.Count(((string, bool, bool) c) => c.Item2 == c.Item3);
			static bool SavedBool(string key)
			{
				return Appliers.Keys.OfType<ConfigEntry<bool>>().Single((ConfigEntry<bool> e) => ((ConfigEntryBase)e).Definition.Section == "Lobby Guard" && ((ConfigEntryBase)e).Definition.Key == key).Value;
			}
		}

		private static void Live<T>(ConfigEntry<T> entry, Action<T> apply)
		{
			Action run = delegate
			{
				apply(entry.Value);
			};
			Appliers[(ConfigEntryBase)(object)entry] = run;
			run();
			entry.SettingChanged += delegate
			{
				run();
			};
		}

		private static void LiveApply(ConfigEntryBase entry)
		{
			if (Appliers.TryGetValue(entry, out var value))
			{
				value();
			}
		}

		private static void ImportOldBlockList()
		{
			try
			{
				string path = Path.Combine(Paths.ConfigPath, "ricketywrecked.repo.lobbyguard.cfg");
				if (!File.Exists(path))
				{
					return;
				}
				string text = File.ReadAllLines(path).FirstOrDefault((string l) => l.TrimStart(Array.Empty<char>()).StartsWith("BlockedSteamIds", StringComparison.Ordinal));
				int num = text?.IndexOf('=') ?? (-1);
				if (num >= 0)
				{
					int num2 = LateJoinPlus.Guard.Guard.AddToBlockListQuietly(text.Substring(num + 1).Split(new char[3] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries));
					if (num2 > 0)
					{
						GuardLog.Source.LogInfo($"[Lobby Guard] Copied {num2} Steam ID(s) from the separate Lobby Guard's block list.");
					}
				}
			}
			catch (Exception ex)
			{
				Log.Debug("Could not read the old Lobby Guard block list: " + ex.Message);
			}
		}

		internal static void ApplyPatches(Harmony harmony)
		{
			List<Type> obj = new List<Type>
			{
				typeof(Firewall.OnEventPatch),
				typeof(HostHijack.MasterSwitchPatch),
				typeof(HostHijack.ReplyPatch),
				typeof(VoiceGuard.SpeakerPatch),
				typeof(Watch.EnteredPatch),
				typeof(CheatRpcFilter.ExecuteRpcPatch),
				typeof(ModOnlyObjects.SpawnPatch),
				typeof(ModOnlyObjects.BufferPatch),
				typeof(StartLock.ShopCheckoutPatch),
				typeof(StartLock.ExtractButtonPatch),
				typeof(StartLock.TruckHoldPatch),
				typeof(PublishIds.CreatePatch),
				typeof(PublishIds.JoinOrCreatePatch),
				typeof(PublishIds.RandomOrCreatePatch),
				typeof(LateJoinPlus.MapSync.MapSync.JoinedRoomPatch),
				typeof(LateJoinPlus.MapSync.MapSync.JoinDetectPatch),
				typeof(LateJoinPlus.MapSync.MapSync.LevelDonePatch),
				typeof(LateJoinPlus.MapSync.MapSync.RemoteAvatarPatch)
			};
			int num = 0;
			foreach (Type item in obj)
			{
				try
				{
					PatchRepair.ApplyClass(harmony, item);
					num++;
				}
				catch (Exception ex)
				{
					Log.Warn("Patch " + item.Name + " could not be applied (" + ex.Message + "). That part is disabled; everything else still works.");
				}
			}
			GuardLog.Source.LogInfo(string.Format("Lobby Guard part loaded (block list: {0} Steam IDs, {1}).", LateJoinPlus.Guard.Guard.BlockList.Count, GuardEnabled.Value ? "on" : "off"));
			Log.Debug(num + " Lobby Guard / Map Sync patch(es) applied.");
		}

		internal static void Tick()
		{
			if (GuardEnabled != null && GuardEnabled.Value)
			{
				Watch.Update();
			}
		}

		internal static IEnumerator TakeOver()
		{
			yield return (object)new WaitForSeconds(5f);
			(string, string)[] array = new(string, string)[2]
			{
				("ricketywrecked.repo.lobbyguard", "Lobby Guard"),
				("ricketywrecked.repo.mapsyncfix", "Map Sync Fix")
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (text, text2) = array[i];
				try
				{
					if (Chainloader.PluginInfos.TryGetValue(text, out var value))
					{
						Harmony.UnpatchID(text);
						if ((Object)(object)value.Instance != (Object)null)
						{
							((Behaviour)value.Instance).enabled = false;
						}
						Log.Warn(text2 + " is part of LateJoinPlus now, so the separate " + text2 + " was switched off. You can uninstall it.");
					}
				}
				catch (Exception ex)
				{
					Log.Warn("Could not switch off the separate " + text2 + ": " + ex.Message);
				}
			}
		}
	}
	internal static class PatchRepair
	{
		internal sealed class Expected
		{
			internal string Owner;

			internal string Kind;

			internal Type Class;

			internal MethodBase Original;

			internal HarmonyMethod Method;
		}

		private static readonly List<Expected> Registered = new List<Expected>();

		private const BindingFlags Methods = BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		internal static Action RebuildMenu;

		internal static Action RestoreRuntime;

		internal static Action RestoreListeners;

		internal static Func<bool> Waiting;

		internal static int Total => Registered.Count;

		internal static int Present => Registered.Count((Expected e) => Copies(e) > 0);

		internal static bool AnyMissing => Registered.Any((Expected e) => Copies(e) == 0);

		internal static List<string> Missing()
		{
			return (from e in Registered
				where Copies(e) == 0
				select e.Class.FullName + "." + e.Method.method.Name + " on " + e.Original.Name + " (" + e.Owner + ")").ToList();
		}

		internal static void ApplyClass(Harmony harmony, Type type)
		{
			MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			MethodInfo methodInfo = methods.FirstOrDefault((MethodInfo m) => m.IsDefined(typeof(HarmonyPrepare), inherit: true) || m.Name == "Prepare");
			if (methodInfo != null && methodInfo.GetParameters().Length == 0 && !(bool)methodInfo.Invoke(null, null))
			{
				return;
			}
			MethodInfo methodInfo2 = methods.FirstOrDefault((MethodInfo m) => m.IsDefined(typeof(HarmonyTargetMethods), inherit: true) || m.Name == "TargetMethods");
			MethodInfo methodInfo3 = methods.FirstOrDefault((MethodInfo m) => m.IsDefined(typeof(HarmonyTargetMethod), inherit: true) || m.Name == "TargetMethod");
			MethodBase[] array = ((methodInfo2 != null) ? ((IEnumerable<MethodBase>)methodInfo2.Invoke(null, null)).ToArray() : ((!(methodInfo3 != null)) ? null : new MethodBase[1] { (MethodBase)methodInfo3.Invoke(null, null) }));
			HarmonyMethod mergedFromType = HarmonyMethodExtensions.GetMergedFromType(type);
			MethodInfo[] array2 = methods;
			foreach (MethodInfo methodInfo4 in array2)
			{
				string text = Kind(methodInfo4);
				if (text != null)
				{
					HarmonyMethod val = HarmonyMethodExtensions.Merge(mergedFromType, HarmonyMethodExtensions.GetMergedFromMethod((MethodBase)methodInfo4));
					val.method = methodInfo4;
					MethodBase[] array3 = array ?? new MethodBase[1] { Resolve(val) };
					foreach (MethodBase original in array3)
					{
						Remember(harmony, type, original, val, text);
					}
				}
			}
			Expected[] source = Registered.Where((Expected e) => e.Class == type && e.Owner == harmony.Id).ToArray();
			if (source.Any((Expected e) => Copies(e) > 0))
			{
				foreach (Expected item in source.Where((Expected e) => Copies(e) == 0))
				{
					Install(item);
				}
				return;
			}
			harmony.CreateClassProcessor(type).Patch();
		}

		private static string Kind(MethodInfo m)
		{
			(string, Type)[] array = new(string, Type)[5]
			{
				("Prefix", typeof(HarmonyPrefix)),
				("Postfix", typeof(HarmonyPostfix)),
				("Transpiler", typeof(HarmonyTranspiler)),
				("Finalizer", typeof(HarmonyFinalizer)),
				("ILManipulator", typeof(HarmonyILManipulator))
			};
			for (int i = 0; i < array.Length; i++)
			{
				(string, Type) tuple = array[i];
				if (m.Name == tuple.Item1 || m.IsDefined(tuple.Item2, inherit: true))
				{
					return tuple.Item1;
				}
			}
			return null;
		}

		private static MethodBase Resolve(HarmonyMethod m)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected I4, but got Unknown
			MethodType valueOrDefault = m.methodType.GetValueOrDefault();
			switch ((int)valueOrDefault)
			{
			case 1:
				return AccessTools.PropertyGetter(m.declaringType, m.methodName);
			case 2:
				return AccessTools.PropertySetter(m.declaringType, m.methodName);
			case 3:
				return AccessTools.Constructor(m.declaringType, m.argumentTypes, false);
			case 4:
				return m.declaringType.TypeInitializer;
			case 0:
				return AccessTools.Method(m.declaringType, m.methodName, m.argumentTypes, (Type[])null);
			default:
			{
				MethodType? methodType = m.methodType;
				throw new NotSupportedException("Patch target kind: " + methodType.ToString());
			}
			}
		}

		private static void Remember(Harmony h, Type type, MethodBase original, HarmonyMethod method, string kind)
		{
			if (original == null)
			{
				throw new MissingMethodException("Patch target for " + type.FullName);
			}
			if (!Registered.Any((Expected e) => e.Owner == h.Id && e.Original == original && e.Method.method == method.method && e.Kind == kind))
			{
				HarmonyMethod val = HarmonyMethodExtensions.Clone(method);
				val.method = method.method;
				Registered.Add(new Expected
				{
					Owner = h.Id,
					Class = type,
					Original = original,
					Method = val,
					Kind = kind
				});
			}
		}

		internal static void ApplyPrefix(Harmony h, MethodBase original, HarmonyMethod prefix)
		{
			Remember(h, prefix.method.DeclaringType, original, prefix, "Prefix");
			if (Copies(Registered.Single((Expected p) => p.Owner == h.Id && p.Original == original && p.Method.method == prefix.method && p.Kind == "Prefix")) == 0)
			{
				h.Patch(original, prefix, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void Install(Expected e)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			PatchProcessor val = new Harmony(e.Owner).CreateProcessor(e.Original);
			switch (e.Kind)
			{
			case "Prefix":
				val.AddPrefix(e.Method);
				break;
			case "Postfix":
				val.AddPostfix(e.Method);
				break;
			case "Transpiler":
				val.AddTranspiler(e.Method);
				break;
			case "Finalizer":
				val.AddFinalizer(e.Method);
				break;
			case "ILManipulator":
				val.AddILManipulator(e.Method);
				break;
			}
			val.Patch();
		}

		internal static int Copies(Expected e)
		{
			Patches patchInfo = Harmony.GetPatchInfo(e.Original);
			if (patchInfo == null || !patchInfo.Owners.Contains(e.Owner))
			{
				return 0;
			}
			return ((e.Kind == "Prefix") ? patchInfo.Prefixes : ((e.Kind == "Postfix") ? patchInfo.Postfixes : ((e.Kind == "Transpiler") ? patchInfo.Transpilers : ((e.Kind == "Finalizer") ? patchInfo.Finalizers : patchInfo.ILManipulators)))).Count((Patch p) => p.owner == e.Owner && p.PatchMethod == e.Method.method);
		}

		internal static int Restore(string mod = null)
		{
			try
			{
				RestoreRuntime?.Invoke();
			}
			catch (Exception ex)
			{
				Log.Warn("Couldn't restore runtime settings: " + ex.Message);
			}
			int num = 0;
			foreach (IGrouping<Type, Expected> item in from e in Registered.ToArray()
				group e by e.Class)
			{
				foreach (Expected item2 in item.Where((Expected e) => Copies(e) == 0))
				{
					try
					{
						Install(item2);
						if (Copies(item2) == 1)
						{
							num++;
						}
						else
						{
							Log.Warn("Patch still missing: " + item2.Class.FullName + "." + item2.Method.method.Name);
						}
					}
					catch (Exception ex2)
					{
						Log.Warn("Couldn't put back " + item2.Class.FullName + ": " + ex2.Message);
					}
				}
			}
			if (mod != null)
			{
				Log.Info("Put back " + num + " of LateJoinPlus's patches that " + mod + " had removed.");
			}
			else if (num > 0)
			{
				Log.Warn("Put back " + num + " missing patches from " + typeof(Plugin).Assembly.GetName().Name + ".dll. The remover is unknown. Loaded plugin assemblies: " + string.Join(", ", Chainloader.PluginInfos.Values.Select((PluginInfo p) => Path.GetFileName(p.Location)).Distinct()) + ".");
			}
			try
			{
				RestoreListeners?.Invoke();
				if (num > 0 || mod != null)
				{
					RebuildMenu?.Invoke();
				}
			}
			catch (Exception ex3)
			{
				Log.Warn("Couldn't restore the open main menu: " + ex3.Message);
			}
			return num;
		}

		internal static IEnumerator CheckAfterStartup()
		{
			yield return (object)new WaitForSecondsRealtime(10f);
			while (Waiting?.Invoke() ?? false)
			{
				yield return (object)new WaitForSecondsRealtime(1f);
			}
			if (AnyMissing)
			{
				Restore();
			}
		}
	}
	[BepInPlugin("ricketywrecked.repo.latejoinplus", "LateJoinPlus", "1.2.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private sealed class Runner : MonoBehaviour
		{
			private void Awake()
			{
				SafeLogging.RunnerExists = true;
			}

			private void OnApplicationQuit()
			{
				SafeLogging.RunnerExists = false;
				SafeLogging.Flush(all: true);
			}

			private void OnDestroy()
			{
				SafeLogging.RunnerExists = false;
				SafeLogging.Flush(all: true);
			}

			private void Update()
			{
				try
				{
					CheatRpcFilter.TrimWindows();
				}
				catch
				{
				}
				try
				{
					GuardLog.Flush();
				}
				catch
				{
				}
				try
				{
					ConsoleGuard.Tick();
				}
				catch
				{
				}
				try
				{
					BugReportLogs.Tick();
				}
				catch (Exception error)
				{
					PhoneErrors.Report("Moderation.BugReportLogs.Tick", error);
				}
				try
				{
					ConflictPopup.Tick();
				}
				catch (Exception error2)
				{
					PhoneErrors.Report("Moderation.ConflictPopup.Tick", error2);
				}
				try
				{
					ModSwitch.Tick();
				}
				catch (Exception error3)
				{
					PhoneErrors.Report("Moderation.ModSwitch.Tick", error3);
				}
				if (!PunGate.PhotonInitialised)
				{
					return;
				}
				try
				{
					Parts.Tick();
				}
				catch (Exception error4)
				{
					PhoneErrors.Report("Parts.Tick", error4);
				}
				try
				{
					MissingRooms.Tick();
				}
				catch (Exception error5)
				{
					PhoneErrors.Report("MissingRooms.Tick", error5);
				}
				try
				{
					Handshake.Tick();
				}
				catch (Exception error6)
				{
					PhoneErrors.Report("Handshake.Tick", error6);
				}
				try
				{
					Hub.Tick();
				}
				catch (Exception error7)
				{
					PhoneErrors.Report("Moderation.Hub.Tick", error7);
				}
				try
				{
					CjkFont.Tick();
				}
				catch (Exception error8)
				{
					PhoneErrors.Report("Moderation.CjkFont.Tick", error8);
				}
				try
				{
					AdminPanel.Tick();
				}
				catch (Exception error9)
				{
					PhoneErrors.Report("Moderation.AdminPanel.Tick", error9);
				}
				try
				{
					CallPhone.Tick();
				}
				catch (Exception error10)
				{
					PhoneErrors.Report("CallPhone.Tick", error10);
				}
				try
				{
					SettingsLink.Tick?.Invoke();
				}
				catch (Exception error11)
				{
					PhoneErrors.Report("Settings.SettingsLink.Tick?.Invoke", error11);
				}
				if (PunGate.Ready)
				{
					try
					{
						InventoryGuard.TrackSpots();
					}
					catch (Exception error12)
					{
						PhoneErrors.Report("LateJoinPlus.Join.InventoryGuard.TrackSpots", error12);
					}
					try
					{
						LobbyGate.Tick();
					}
					catch (Exception error13)
					{
						PhoneErrors.Report("LobbyGate.Tick", error13);
					}
					try
					{
						SteamLobbyCheck.Tick();
					}
					catch (Exception error14)
					{
						PhoneErrors.Report("SteamLobbyCheck.Tick", error14);
					}
					try
					{
						RoomNamePrefix.Tick();
					}
					catch (Exception error15)
					{
						PhoneErrors.Report("RoomNamePrefix.Tick", error15);
					}
					try
					{
						PlayerLimit.Tick();
					}
					catch (Exception error16)
					{
						PhoneErrors.Report("PlayerLimit.Tick", error16);
					}
					try
					{
						PhotonCacheCleaner.Tick();
					}
					catch (Exception error17)
					{
						PhoneErrors.Report("PhotonCacheCleaner.Tick", error17);
					}
					try
					{
						ModuleEstimate.Tick();
					}
					catch (Exception error18)
					{
						PhoneErrors.Report("ModuleEstimate.Tick", error18);
					}
					try
					{
						LevelSnapshot.Tick();
					}
					catch (Exception error19)
					{
						PhoneErrors.Report("LevelSnapshot.Tick", error19);
					}
					try
					{
						TruckHealBackup.Tick();
					}
					catch (Exception error20)
					{
						PhoneErrors.Report("TruckHealBackup.Tick", error20);
					}
				}
			}

			private void OnGUI()
			{
				try
				{
					StatusOverlay.Draw();
					CallOverlay.Draw();
					CallOverlay.DrawActions();
					LoadingPlayers.Draw();
					StuckReport.Draw();
					AdminPanel.Draw();
				}
				catch (Exception error)
				{
					PhoneErrors.Report("Phone draw prerequisites", error);
				}
				try
				{
					CallPhone.Draw();
				}
				catch (Exception error2)
				{
					PhoneErrors.Report("CallPhone.Draw", error2);
				}
				ConflictPopup.Draw();
			}
		}

		internal const string Guid = "ricketywrecked.repo.latejoinplus";

		internal const string Version = "1.2.2";

		private static readonly Dictionary<string, string> LobbyListMods = new Dictionary<string, string> { { "com.repo.kr.ShowMoreLobbyPlayers", "ShowMoreLobbyPlayers (kr_zhou)" } };

		private static readonly Dictionary<string, string> Superseded = new Dictionary<string, string>
		{
			{ "ozoka.latejoin", "LateJoin (Ozoka Gaming)" },
			{ "chaos.holz.laterepo", "LateRepo (Chaosholz)" },
			{ "laterepo.fix.runtime", "LateRepo Fix (AST Studios)" },
			{ "jp.laterepo.introfix", "LateRepo Intro Fix (CapackMods)" },
			{ "knightmike.latejoin", "Late Join (knightmike)" },
			{ "zichen.latejoinnow", "LateJoinNow (Zichen)" },
			{ "com.repo.latejoinfixed", "LateJoinFixed (Scorpio)" },
			{ "rebateman.latejoin", "Late Join (Rebateman)" },
			{ "repolatejoin.unified", "LateJoin" }
		};

		private static readonly string[] BannerArt = new string[6] { " _           _         ___       _      ______ _", "| |         | |       |_  |     (_)     | ___ \\ |", "| |     __ _| |_ ___    | | ___  _ _ __ | |_/ / |_   _ ___", "| |    / _` | __/ _ \\   | |/ _ \\| | '_ \\|  __/| | | | / __|", "| |___| (_| | ||  __/\\__/ / (_) | | | | | |   | | |_| \\__ \\", "\\_____/\\__,_|\\__\\___\\____/ \\___/|_|_| |_\\_|   |_|\\__,_|___/" };

		private Harmony _harmony;

		private bool _photonSetup;

		private static Dictionary<string, string> ModerationMods => ModConfig.Conflicts.ToDictionary((ModConfig.Conflict e) => e.Guid, (ModConfig.Conflict e) => e.Name);

		private static IEnumerable<string> Banner()
		{
			int width = BannerArt.Max((string l) => l.Length);
			string edge = "+" + new string('=', width + 2) + "+";
			yield return edge;
			string[] bannerArt = BannerArt;
			foreach (string text in bannerArt)
			{
				yield return Row(text);
			}
			yield return Row("");
			yield return Centre("v1.2.2  -  join any time, no invisible rooms");
			yield return Centre("Lobby Guard anti-cheat  -  by RicketyWrecked");
			yield return edge;
			string Centre(string text2)
			{
				return Row(new string(' ', Math.Max(0, (width - text2.Length) / 2)) + text2);
			}
			string Row(string text2)
			{
				return "| " + text2.PadRight(width) + " |";
			}
		}

		private void Awake()
		{
			Log.Attach(((BaseUnityPlugin)this).Logger);
			ModConfig.BindConflicts(((BaseUnityPlugin)this).Config);
			if (ModConfig.KeptConflicts.Length != 0)
			{
				L.Bind(((BaseUnityPlugin)this).Config);
				((BaseUnityPlugin)this).Logger.LogInfo((object)("LateJoinPlus is off: you chose to keep " + string.Join(", ", ModConfig.KeptConflicts.Select((ModConfig.Conflict e) => e.Name)) + ". Late joining stays off too."));
				((Component)this).gameObject.AddComponent<OffNotice>();
			}
			else
			{
				StartEnabled();
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void StartEnabled()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			Stopwatch stopwatch = Stopwatch.StartNew();
			ModConfig.Bind(((BaseUnityPlugin)this).Config);
			L.Bind(((BaseUnityPlugin)this).Config);
			Parts.Bind(((BaseUnityPlugin)this).Config);
			PlayerLimit.Watch();
			Hub.Init();
			GameObject val = new GameObject("LateJoinPlus")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			Runner runner = val.AddComponent<Runner>();
			val.AddComponent<ConsoleGuardNames>();
			JoinQueue.Attach((MonoBehaviour)runner);
			PatchRepair.Waiting = () => ConflictPopup.IsOpen;
			((MonoBehaviour)runner).StartCoroutine(PatchRepair.CheckAfterStartup());
			SteamLobbyCheck.Attach((MonoBehaviour)(object)runner);
			_harmony = new Harmony("ricketywrecked.repo.latejoinplus");
			PatchRepair.RestoreRuntime = delegate
			{
				Parts.RestoreSettings();
				Hub.RestoreOwnRuntime();
				if (Chainloader.PluginInfos.ContainsKey("nickklmao.menulib"))
				{
					ApplySettingsMenu();
				}
			};
			PatchRepair.RestoreListeners = ResumePhoton;
			PlayerLimit.TakeOver(_harmony);
			int num = ApplyPatches("LateJoinPlus.Patches");
			if (Chainloader.PluginInfos.ContainsKey("nickklmao.menulib"))
			{
				ApplySettingsMenu();
			}
			else
			{
				Log.Info("MenuLib isn't installed, so there's no LATE JOIN button in the main menu; the settings are in the config file (or REPOConfig).");
			}
			((MonoBehaviour)runner).StartCoroutine(Parts.TakeOver());
			((MonoBehaviour)runner).StartCoroutine(AdminHub.NoteOtherAdminMod());
			((MonoBehaviour)runner).StartCoroutine(KeyClashes.LogLater());
			((MonoBehaviour)runner).StartCoroutine(OtherLateJoinMods.TakeOver(Superseded));
			((MonoBehaviour)runner).StartCoroutine(OtherLateJoinMods.TakeOver(ModerationMods, null, "moderation", null));
			((MonoBehaviour)runner).StartCoroutine(OtherLateJoinMods.TakeOver(LobbyListMods, null, "the lobby player list", null));
			PunGate.Initialised += ResumePhoton;
			foreach (string item in Banner())
			{
				Log.Info(item);
			}
			Log.Info("LateJoinPlus 1.2.2 loaded. Late join " + (ModConfig.On ? "on" : "off") + ", debug logging " + (Log.DebugOn ? "on" : "off") + ".");
			Log.Debug(num + " patch group(s) applied before Photon start.");
			Log.Info("Timing: start-up took " + stopwatch.ElapsedMilliseconds + " ms.");
		}

		private void ResumePhoton()
		{
			if (!PunGate.PhotonInitialised)
			{
				return;
			}
			if (!_photonSetup)
			{
				Stopwatch stopwatch = Stopwatch.StartNew();
				ApplyPatches("LateJoinPlus.Patches.Late");
				Parts.ApplyPatches(_harmony);
				try
				{
					PatchRepair.ApplyClass(_harmony, typeof(SteamLobbyCheck.BroadcastPatch));
				}
				catch (Exception ex)
				{
					Log.Warn("Steam lobby broadcast patch could not be applied (" + ex.Message + "). Invites may not work for everyone.");
				}
				Log.Info("Timing: late patches took " + stopwatch.ElapsedMilliseconds + " ms.");
				_photonSetup = true;
			}
			Handshake.Listen();
			LevelSnapshot.Listen();
			Hub.Listen();
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private void ApplySettingsMenu()
		{
			try
			{
				SettingsMenu.Apply(_harmony, ((BaseUnityPlugin)this).Config);
			}
			catch (Exception ex)
			{
				Log.Warn("Could not add the LATE JOIN main menu button: " + ex.Message);
			}
		}

		private int ApplyPatches(string ns)
		{
			Type[] array;
			try
			{
				array = typeof(Plugin).Assembly.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				array = ex.Types.Where((Type t) => t != null).ToArray();
				Log.Warn("Some of LateJoinPlus's classes couldn't be loaded (" + (ex.LoaderExceptions?.FirstOrDefault()?.Message ?? ex.Message) + "); applying the rest.");
			}
			catch (Exception ex2)
			{
				Log.Error("Could not enumerate patch classes: " + ex2);
				return 0;
			}
			List<Type> list = new List<Type>();
			Type[] array2 = array;
			foreach (Type type in array2)
			{
				try
				{
					if (type.Namespace == ns && type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0)
					{
						list.Add(type);
					}
				}
				catch (Exception ex3)
				{
					Log.Warn("Patch group " + type.Name + " could not be read (" + ex3.GetType().Name + ": " + ex3.Message + "). That feature is disabled; everything else still works.");
				}
			}
			Type[] array3 = list.ToArray();
			int num2 = 0;
			array2 = array3;
			foreach (Type type2 in array2)
			{
				try
				{
					PatchRepair.ApplyClass(_harmony, type2);
					num2++;
					Log.Debug("Applied patch group " + type2.Name + ".");
				}
				catch (Exception ex4)
				{
					Log.Warn("Patch group " + type2.Name + " could not be applied (" + ex4.GetType().Name + ": " + ex4.Message + "). That feature is disabled; everything else still works.");
				}
			}
			return num2;
		}
	}
	internal static class Report
	{
		private sealed class Counts
		{
			internal int Joins;

			internal int WithMod;

			internal int Loaded;

			internal int LeftEarly;

			internal int Stuck;

			internal int MapReveals;

			internal int RoomsRevealed;

			internal int ExtractionOpened;

			internal int ExtractionSkipped;

			internal int SoftlocksPrevented;

			internal int AutoPressesIgnored;

			internal int Blocked;

			internal int Banned;

			internal int SlowSteps;

			internal int SteamRebuilt;

			internal int SteamResent;

			internal int CheatsIgnored;

			internal double SlowestStepMs;

			internal readonly List<float> LoadSeconds = new List<float>();

			internal bool Empty
			{
				get
				{
					if (Joins == 0 && Blocked == 0 && Banned == 0 && SoftlocksPrevented == 0 && SlowSteps == 0 && SteamRebuilt == 0 && SteamResent == 0)
					{
						return CheatsIgnored == 0;
					}
					return false;
				}
			}

			internal void Add(Counts o)
			{
				Joins += o.Joins;
				WithMod += o.WithMod;
				Loaded += o.Loaded;
				LeftEarly += o.LeftEarly;
				Stuck += o.Stuck;
				MapReveals += o.MapReveals;
				RoomsRevealed += o.RoomsRevealed;
				ExtractionOpened += o.ExtractionOpened;
				ExtractionSkipped += o.ExtractionSkipped;
				SoftlocksPrevented += o.SoftlocksPrevented;
				AutoPressesIgnored += o.AutoPressesIgnored;
				Blocked += o.Blocked;
				Banned += o.Banned;
				SlowSteps += o.SlowSteps;
				SteamRebuilt += o.SteamRebuilt;
				SteamResent += o.SteamResent;
				CheatsIgnored += o.CheatsIgnored;
				SlowestStepMs = Math.Max(SlowestStepMs, o.SlowestStepMs);
				LoadSeconds.AddRange(o.LoadSeconds);
			}
		}

		private static Counts _level = new Counts();

		private static Counts Session = new Counts();

		private static string _levelName;

		private static int _levels;

		private static bool _quitHooked;

		private static bool Hosting
		{
			get
			{
				if (PhotonNetwork.InRoom)
				{
					return PhotonNetwork.IsMasterClient;
				}
				return false;
			}
		}

		internal static void Joined()
		{
			if (Hosting)
			{
				_level.Joins++;
			}
		}

		internal static void Loaded(float seconds, bool withMod)
		{
			_level.Loaded++;
			_level.LoadSeconds.Add(seconds);
			if (withMod)
			{
				_level.WithMod++;
			}
		}

		internal static void LeftEarly()
		{
			_level.LeftEarly++;
		}

		internal static void Stuck()
		{
			_level.Stuck++;
		}

		internal static void NotStuck()
		{
			if (_level.Stuck > 0)
			{
				_level.Stuck--;
			}
		}

		internal static void MapRevealed(int rooms)
		{
			_level.MapReveals++;
			_level.RoomsRevealed += rooms;
		}

		internal static void ExtractionOpened()
		{
			_level.ExtractionOpened++;
		}

		internal static void ExtractionSkipped()
		{
			_level.ExtractionSkipped++;
		}

		internal static void SoftlockPrevented()
		{
			_level.SoftlocksPrevented++;
		}

		internal static void AutoPressIgnored()
		{
			_level.AutoPressesIgnored++;
		}

		internal static void Blocked()
		{
			_level.Blocked++;
		}

		internal static void Banned()
		{
			_level.Banned++;
		}

		internal static void CheatIgnored()
		{
			_level.CheatsIgnored++;
		}

		internal static void SteamLobbyRebuilt()
		{
			_level.SteamRebuilt++;
		}

		internal static void SteamLobbyResent()
		{
			_level.SteamResent++;
		}

		internal static void SlowStep(double ms)
		{
			_level.SlowSteps++;
			_level.SlowestStepMs = Math.Max(_level.SlowestStepMs, ms);
		}

		internal static void LevelStarting()
		{
			HookQuit();
			Flush("Level '" + (_levelName ?? "?") + "'", _level);
			Session.Add(_level);
			if (!_level.Empty)
			{
				_levels++;
			}
			_level = new Counts();
			_levelName = SafeLevelName();
			if (!PhotonNetwork.InRoom && !Session.Empty)
			{
				Flush("Session (" + _levels + " level(s) with activity)", Session);
				Session = new Counts();
				_levels = 0;
			}
		}

		private static void HookQuit()
		{
			if (_quitHooked)
			{
				return;
			}
			_quitHooked = true;
			Application.quitting += delegate
			{
				try
				{
					Session.Add(_level);
					Flush("Session (" + _levels + " level(s) with activity)", Session);
				}
				catch
				{
				}
			};
		}

		private static void Flush(string what, Counts c)
		{
			if (!c.Empty)
			{
				string text = ((c.LoadSeconds.Count == 0) ? "-" : ("avg " + c.LoadSeconds.Average().ToString("0.0") + " s, slowest " + c.LoadSeconds.Max().ToString("0.0") + " s"));
				int num = Math.Max(0, c.Joins - c.Loaded - c.LeftEarly - c.Stuck);
				bool flag = c.Stuck == 0;
				Log.Info("[Report] " + what + ": " + (flag ? "OK" : "CHECK") + " | joins " + c.Joins + " (" + c.WithMod + " with LateJoinPlus), loaded " + c.Loaded + " (" + text + "), left while loading " + c.LeftEarly + ", still loading at level end " + num + ", stuck " + c.Stuck + " | map reveal " + c.MapReveals + " (" + c.RoomsRevealed + " rooms) | extraction: opened for joiner " + c.ExtractionOpened + ", already had it " + c.ExtractionSkipped + ", softlocks prevented " + c.SoftlocksPrevented + ", auto-presses ignored " + c.AutoPressesIgnored + " | Lobby Guard: blocked " + c.Blocked + ", banned " + c.Banned + ", cheats ignored " + c.CheatsIgnored + " | Steam lobby: rebuilt " + c.SteamRebuilt + ", re-sent to players " + c.SteamResent + " | slow catch-up steps " + c.SlowSteps + ((c.SlowSteps > 0) ? (" (slowest " + c.SlowestStepMs.ToString("0") + " ms)") : ""));
			}
		}

		private static string SafeLevelName()
		{
			try
			{
				return ((Object)(object)RunManager.instance != (Object)null && (Object)(object)RunManager.instance.levelCurrent != (Object)null) ? ((Object)RunManager.instance.levelCurrent).name : null;
			}
			catch
			{
				return null;
			}
		}
	}
	internal static class TruckHealBackup
	{
		private const float WaitSeconds = 6f;

		private static readonly FieldInfo HealerStateField = Reflect.Field(typeof(TruckHealer), "currentState");

		private static readonly FieldInfo FinalHealField = Reflect.Field(typeof(PlayerAvatar), "finalHeal");

		private static readonly FieldInfo DeadSetField = Reflect.Field(typeof(PlayerAvatar), "deadSet");

		private static readonly FieldInfo DisabledField = Reflect.Field(typeof(PlayerAvatar), "isDisabled");

		private static readonly FieldInfo InTruckField = Reflect.Field(typeof(RoomVolumeCheck), "inTruck");

		private static readonly Dictionary<int, float> Since = new Dictionary<int, float>();

		private static readonly Dictionary<int, float> Healed = new Dictionary<int, float>();

		private static object _level;

		private static float _next;

		internal static void Tick()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_00ce: Invalid comparison between Unknown and I4
			try
			{
				if (Time.unscaledTime < _next)
				{
					return;
				}
				_next = Time.unscaledTime + 0.5f;
				object obj = ((SemiFunc.RunIsLevel() && (Object)RunManager.instance != (Object)null) ? RunManager.instance.levelCurrent : null);
				if (obj == null || obj != _level)
				{
					_level = obj;
					Since.Clear();
					Healed.Clear();
				}
				if (obj == null || !PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient || ModConfig.TruckHealBackup == null || !ModConfig.TruckHealBackup.Value)
				{
					return;
				}
				TruckHealer instance = TruckHealer.instance;
				if ((Object)instance == (Object)null || !(HealerStateField?.GetValue(instance) is State val) || (int)val != 2)
				{
					return;
				}
				foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
				{
					Check(player);
				}
			}
			catch (Exception ex)
			{
				Log.Debug("Truck heal backup: " + ex.Message);
			}
		}

		private static void Check(PlayerAvatar avatar)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Expected O, but got Unknown
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			if ((Object)avatar == (Object)null || (Object)avatar.photonView == (Object)null || avatar.photonView.IsMine)
			{
				return;
			}
			int viewID = avatar.photonView.ViewID;
			bool flag = Reflect.Get(FinalHealField, avatar, fallback: false);
			if (Healed.TryGetValue(viewID, out var value))
			{
				if (flag && value > 0f)
				{
					Healed[viewID] = -1f;
					Log.Info("[Truck heal] " + Name(avatar) + "'s own truck heal arrived " + (int)(Time.unscaledTime - value) + " s after the backup one (so they got both this time).");
				}
				return;
			}
			bool inTruck = (Object)avatar.RoomVolumeCheck != (Object)null && Reflect.Get(InTruckField, avatar.RoomVolumeCheck, fallback: false);
			bool down = Reflect.Get(DeadSetField, avatar, fallback: false) || Reflect.Get(DisabledField, avatar, fallback: false);
			float value2;
			if (!Waiting(inTruck, flag, down) || (Object)avatar.playerHealth == (Object)null)
			{
				Since.Remove(viewID);
			}
			else if (!Since.TryGetValue(viewID, out value2))
			{
				Since[viewID] = Time.unscaledTime;
			}
			else if (Due(value2, Time.unscaledTime))
			{
				int num = Amount(SemiFunc.MoonLevel());
				avatar.playerHealth.HealOther(num, true);
				Healed[viewID] = Time.unscaledTime;
				Since.Remove(viewID);
				Log.Info("[Truck heal] " + Name(avatar) + " stood in the truck " + 6 + " s after its heal opened, but their game didn't heal them; healed them from here (+" + num + ").");
			}
		}

		internal static bool Waiting(bool inTruck, bool healedOwn, bool down)
		{
			if (inTruck && !healedOwn)
			{
				return !down;
			}
			return false;
		}

		internal static bool Due(float since, float now)
		{
			return now - since >= 6f;
		}

		internal static int Amount(int moon)
		{
			if (moon < 2)
			{
				if (moon != 1)
				{
					return 50;
				}
				return 35;
			}
			return 25;
		}

		private static string Name(PlayerAvatar avatar)
		{
			Player owner = avatar.photonView.Owner;
			return LateJoinPlus.Guard.Guard.Trim(((owner != null) ? owner.NickName : null) ?? ("player " + avatar.photonView.OwnerActorNr));
		}
	}
}
namespace LateJoinPlus.Moderation
{
	internal static class AdminPanel
	{
		internal enum Page
		{
			Home,
			Lobby,
			Players,
			Upgrades,
			Spawn,
			Items,
			Run,
			World
		}

		internal sealed class Person
		{
			internal int Actor;

			internal string Name;

			internal bool You;

			internal bool Host;

			internal bool Mod;

			internal bool Protected;

			internal bool Present;

			internal bool Dead;

			internal int Hp;

			internal int MaxHp;

			internal string SteamId;

			internal string GameId;

			internal string LateJoin;

			internal bool GameTools;

			internal Demo.Person Made;
		}

		internal sealed class Spawnable
		{
			internal string Kind;

			internal string Key;

			internal string Name;

			internal string Group;

			internal bool Modded;
		}

		private static readonly (Page Page, string Name)[] Pages = new(Page, string)[8]
		{
			(Page.Home, L.N("Home")),
			(Page.Lobby, L.N("Lobby")),
			(Page.Players, L.N("Players")),
			(Page.Upgrades, L.N("Upgrades")),
			(Page.Spawn, L.N("Spawn")),
			(Page.Items, L.N("Items")),
			(Page.Run, L.N("Run")),
			(Page.World, L.N("World"))
		};

		internal static Rect WindowRect;

		internal static Page Current = Page.Home;

		internal static int Selected;

		private const string FindField = "ljp-admin-find";

		private static bool _unfocus;

		private static bool _focusFind;

		private static string _confirm;

		private static float _confirmUntil;

		private static int _lobbyPage;

		private static int _playersPage;

		private static int _spawnPage;

		private static int _levelPage;

		private static bool _modUpgrades;

		private static int _modUpgradePage;

		internal static string SpawnKind = "all";

		private static string _group = "";

		private static int _spawnCount = 1;

		internal static int SpawnAt;

		internal static bool CloseAfterSpawn;

		internal static string Find = "";

		private static readonly List<Spawnable> Recent = new List<Spawnable>();

		internal static readonly Dictionary<string, int> ShownUpgrades = new Dictionary<string, int>();

		internal static string ShownUpgradesFor;

		private static readonly Dictionary<string, (int Value, float Until)> Held = new Dictionary<string, (int, float)>();

		private static readonly List<InputKey> StillWorks = new List<InputKey>
		{
			(InputKey)25,
			(InputKey)32
		};

		private static float _x;

		private static float _y;

		private const float W = 1240f;

		private const float H = 760f;

		private const float ContentX = 236f;

		private const float ContentY = 84f;

		private const float ContentW = 984f;

		private const float ContentH = 656f;

		private const float Gap = 14f;

		private const int LobbyPerPage = 10;

		private const int PlayersPerPage = 10;

		private static readonly Dictionary<int, string> SendToPicks = new Dictionary<int, string>();

		private static string _upgradesLogged;

		private static readonly string[] KindKeys = new string[5] { "all", "item", "valuable", "enemy", "cosmetic" };

		private static readonly string[] KindNames = new string[5]
		{
			L.N("All"),
			L.N("Items"),
			L.N("Valuables"),
			L.N("Enemies"),
			L.N("Cosmetic boxes")
		};

		private static readonly Dictionary<string, (List<Spawnable> List, float At, bool Demo)> SpawnCache = new Dictionary<string, (List<Spawnable>, float, bool)>();

		private static List<Spawnable> _favourites;

		private static readonly List<Spawnable> DemoFavourites = new List<Spawnable>();

		private static int _itemsPage;

		private const int LevelsPerPage = 10;

		private static int _demoWorld = 8;

		private static readonly Dictionary<int, int> DemoPowers = new Dictionary<int, int>();

		internal static bool IsOpen { get; private set; }

		internal static bool Typing { get; private set; }

		internal static string ConfirmArmed
		{
			get
			{
				if (!(Time.unscaledTime < _confirmUntil))
				{
					return null;
				}
				return _confirm;
			}
		}

		internal static int SpawnShown { get; private set; }

		internal static IEnumerable<Spawnable> PhoneRecent => Recent.Take(6);

		internal static bool Allowed => AdminHub.MayUse;

		private static bool Hosting
		{
			get
			{
				if (PhotonNetwork.InRoom)
				{
					return PhotonNetwork.IsMasterClient;
				}
				return false;
			}
		}

		private static float S => Ui.S;

		private static string FavouritesFile => Path.Combine(Paths.ConfigPath, "LateJoinPlus-admin-favourites.txt");

		internal static void Open(int actor = -1)
		{
			if (!Allowed)
			{
				StatusOverlay.ShowNotice((!PhotonNetwork.InRoom) ? L.T("Admin works in a lobby you host or moderate.") : L.T("The Admin page is for the host and moderators allowed Admin."), 4f);
				return;
			}
			if (actor >= 0)
			{
				Selected = actor;
				Current = Page.Players;
			}
			AdminHub.AskState();
			if (!IsOpen)
			{
				IsOpen = true;
				Ui.Click();
				HoldGame();
				ModLog.Menu("Admin panel opened" + (Hosting ? " (as host)." : " (as moderator)."));
			}
		}

		internal static void Close()
		{
			if (IsOpen)
			{
				IsOpen = false;
				Typing = false;
				_unfocus = true;
				_confirm = null;
				Ui.Click();
				GameCursor.Release();
			}
		}

		internal static void Toggle()
		{
			if (IsOpen)
			{
				Close();
			}
			else
			{
				Open();
			}
		}

		internal static bool Escape()
		{
			if (Typing)
			{
				_unfocus = true;
				return false;
			}
			Close();
			return true;
		}

		internal static void Tick()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			if (!IsOpen)
			{
				return;
			}
			if (!Allowed || !PhotonNetwork.InRoom)
			{
				Close();
			}
			else if (!Input.GetKeyDown((KeyCode)27) || !Escape())
			{
				HoldGame();
				if (Typing && (Object)MenuManager.instance != (Object)null)
				{
					MenuManager.instance.TextInputActive();
				}
			}
		}

		private static void HoldGame()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			GameCursor.Free(0.2f);
			InputManager instance = InputManager.instance;
			if ((Object)instance != (Object)null)
			{
				instance.DisableMovement(0.2f);
				instance.DisableAiming(0.2f);
				instance.DisableControlsExcept(0.2f, StillWorks);
			}
		}

		private static Rect R(float x, float y, float w, float h)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			return new Rect(_x + x * S, _y + y * S, w * S, h * S);
		}

		internal static void Draw()
		{
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Invalid comparison between Unknown and I4
			//IL_0268: 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_0276: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOpen || Event.current == null)
			{
				return;
			}
			Color color = GUI.color;
			Matrix4x4 matrix = GUI.matrix;
			int depth = GUI.depth;
			GUI.matrix = Matrix4x4.identity;
			GUI.color = Color.white;
			GUI.depth = -100;
			float num = Mathf.Min(new float[3]
			{
				Ui.S,
				((float)Screen.width - 16f) / 1240f,
				((float)Screen.height - 16f) / 760f
			});
			Ui.Override = ((num < Ui.S) ? num : 0f);
			try
			{
				if (_unfocus)
				{
					_unfocus = false;
					GUI.FocusControl((string)null);
				}
				StartTypingToFind();
				_x = Mathf.Round(((float)Screen.width - 1240f * S) / 2f);
				_y = Mathf.Round(((float)Screen.height - 760f * S) / 2f);
				Rect r = (WindowRect = R(0f, 0f, 1240f, 760f));
				Ui.Panel(r, new Color(0.06f, 0.05f, 0.04f, 0.97f), Ui.Alpha(Ui.Yellow, 0.6f), 14f, 2f);
				Header();
				int num2;
				if (!Hosting)
				{
					num2 = (Hub.May(Caps.Admin) ? 1 : 0);
					if (num2 == 0)
					{
						goto IL_0169;
					}
				}
				else
				{
					num2 = 1;
				}
				Sidebar();
				goto IL_0169;
				IL_0169:
				if (num2 == 0)
				{
					StartSettingRow(R(236f, 84f, 984f, 52f));
				}
				else
				{
					switch (Current)
					{
					case Page.Home:
						HomePage();
						break;
					case Page.Lobby:
						LobbyPage();
						break;
					case Page.Players:
						PlayersPage();
						break;
					case Page.Upgrades:
						UpgradesPage();
						break;
					case Page.Spawn:
						SpawnPage();
						break;
					case Page.Items:
						ItemsPage();
						break;
					case Page.Run:
						RunPage();
						break;
					case Page.World:
						WorldPage();
						break;
					}
				}
				if (_focusFind && (int)Event.current.type == 7)
				{
					_focusFind = false;
					GUI.FocusControl("ljp-admin-find");
				}
				Typing = GUI.GetNameOfFocusedControl() == "ljp-admin-find";
				if ((int)Event.current.type == 0 && ((Rect)(ref r)).Contains(Event.current.mousePosition) && GUIUtility.hotControl == 0 && GUIUtility.keyboardControl != 0 && !Typing)
				{
					GUI.FocusControl((string)null);
				}
				if ((int)Event.current.type == 0 && ((Rect)(ref r)).Contains(Event.current.mousePosition))
				{
					Event.current.Use();
				}
				GameCursor.Draw();
			}
			catch (Exception ex)
			{
				Log.Debug("Admin panel: " + ex.Message);
			}
			finally
			{
				Ui.Override = 0f;
				GUI.color = color;
				GUI.matrix = matrix;
				GUI.depth = depth;
			}
		}

		private static void StartTypingToFind()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Invalid comparison between Unknown and I4
			Event current = Event.current;
			if ((int)current.type == 4 && !Typing && (Current == Page.Home || Current == Page.Spawn) && char.IsLetterOrDigit(current.character) && !IsTalkKey(current.character))
			{
				Find += current.character;
				_spawnPage = 0;
				_focusFind = true;
				current.Use();
			}
		}

		private static bool IsTalkKey(char c)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//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_002e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				InputManager instance = InputManager.instance;
				if ((Object)instance == (Object)null)
				{
					return false;
				}
				foreach (InputKey stillWork in StillWorks)
				{
					string obj = instance.GetKeyString(stillWork) ?? "";
					string text = obj.Substring(obj.LastIndexOf('/') + 1);
					if (text.Length == 1 && char.ToLowerInvariant(text[0]) == char.ToLowerInvariant(c))
					{
						return true;
					}
				}
			}
			catch
			{
			}
			return false;
		}

		private static void Header()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: 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)
			Ui.Label(R(28f, 16f, 200f, 44f), L.T("Admin").ToUpperInvariant(), 32f, Ui.Yellow, (TextAnchor)3);
			string text = (Hosting ? ("<color=#ffd94a>" + L.T("HOST") + "</color>") : ("<color=#5ed6ff>" + L.T("MODERATOR") + "</color>"));
			Room currentRoom = PhotonNetwork.CurrentRoom;
			int num = ((currentRoom == null) ? 1 : currentRoom.PlayerCount);
			Room currentRoom2 = PhotonNetwork.CurrentRoom;
			int num2 = ((currentRoom2 != null) ? currentRoom2.MaxPlayers : 0);
			string text2 = RunName();
			Ui.Label(R(200f, 16f, 520f, 44f), text + "   " + L.T("Players") + " " + num + ((num2 > 0) ? ("/" + num2) : "") + ((text2.Length > 0) ? ("   <color=#9a948c>" + text2 + "</color>") : ""), 15f, Ui.Muted, (TextAnchor)3);
			float num3 = _x + 1212f * S;
			string text3 = L.T("close");
			float num4 = Ui.Width(text3, 13f) + 6f * S + Mathf.Max(22f * S, Ui.Width("ESC", 13f, bold: true) + 12f * S);
			Ui.Key(num3 - num4, _y + 27f * S, 22f * S, "ESC", text3, 13f);
			ConfigEntry<KeyCode> adminKey = ModConfig.AdminKey;
			string text4 = Ui.KeyCap((KeyCode)((adminKey != null) ? ((int)adminKey.Value) : 0));
			if (text4.Length > 0)
			{
				float num5 = Mathf.Max(22f * S, Ui.Width(text4, 13f, bold: true) + 12f * S) + 10f * S;
				Ui.Key(num3 - num4 - num5, _y + 27f * S, 22f * S, text4, "", 13f);
			}
			Ui.Line(R(24f, 70f, 1192f, 1f), Ui.Alpha(Ui.Yellow, 0.25f));
		}

		internal static string RunName()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			try
			{
				if (SemiFunc.RunIsShop())
				{
					return L.T("The shop");
				}
				if (SemiFunc.RunIsLobby() || SemiFunc.MenuLevel())
				{
					return L.T("Lobby");
				}
				Level val = RunManager.instance?.levelCurrent;
				return ((Object)val != (Object)null) ? AdminCatalog.LevelName(val) : "";
			}
			catch
			{
				return "";
			}
		}

		private static void Sidebar()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			float num = 92f;
			(Page, string)[] pages = Pages;
			for (int i = 0; i < pages.Length; i++)
			{
				(Page, string) tuple = pages[i];
				Rect val = R(20f, num, 200f, 50f);
				bool flag = Current == tuple.Item1;
				bool flag2 = Ui.Hover(val);
				if (flag || flag2)
				{
					Ui.Panel(val, Ui.Alpha(Ui.Yellow, flag ? 0.16f : 0.07f), null, 8f);
				}
				if (flag)
				{
					Ui.Panel(R(20f, num + 10f, 4f, 30f), Ui.Yellow, null, 2f);
				}
				Ui.Label(R(38f, num, 178f, 50f), Ui.Fit(L.T(tuple.Item2).ToUpperInvariant(), 17f, 178f * S), 17f, flag ? Ui.Yellow : Ui.Text, (TextAnchor)3);
				Page item = tuple.Item1;
				string text = "page:" + item;
				Ui.Spots[text] = val;
				if ((GUI.Button(val, GUIContent.none, GUIStyle.none) || Ui.FakeClick(val)) && !flag)
				{
					Ui.Click();
					Ui.LastClicked = text;
					Show(tuple.Item1);
				}
				num += 56f;
			}
			Ui.Paragraph(Ui.Card(R(20f, 620f, 200f, 120f), null), Hosting ? L.T("Moderators you allow Admin can use this menu too. What anyone does here goes in History.") : L.F("The host's game carries these out. At most {0} actions every {1} seconds.", 10, 10), 12f, Ui.Muted, (TextAnchor)0);
		}

		internal static void ResetSpawnChoices()
		{
			SpawnKind = "all";
			_group = "";
			_spawnCount = 1;
			SpawnAt = 0;
			Find = "";
		}

		internal static void Show(Page page)
		{
			Current = page;
			_unfocus = true;
			_confirm = null;
		}

		internal static List<Person> Everyone()
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			List<Person> list = new List<Person>();
			foreach (Player item in from p in PhotonNetwork.PlayerList
				orderby (!p.IsLocal) ? (p.IsMasterClient ? 1 : 2) : 0, p.ActorNumber
				select p)
			{
				int actorNumber = item.ActorNumber;
				PlayerAvatar val = Watch.AvatarOf(actorNumber);
				bool flag = (Object)val != (Object)null;
				list.Add(new Person
				{
					Actor = actorNumber,
					Name = (item.IsLocal ? L.T("You") : (LateJoinPlus.Guard.Guard.Trim(item.NickName) ?? "?")),
					You = item.IsLocal,
					Host = item.IsMasterClient,
					Mod = (!item.IsMasterClient && Hub.IsModerator(actorNumber)),
					Protected = Hub.IsProtected(actorNumber),
					Present = flag,
					Dead = (flag && AdminActions.IsDead(val)),
					Hp = (flag ? AdminActions.HealthOf(val) : 0),
					MaxHp = (flag ? AdminActions.MaxHealthOf(val) : 100),
					SteamId = (item.IsLocal ? Hub.LocalSteamId : LateJoinPlus.Guard.Guard.SteamIdOf(actorNumber)),
					GameId = (flag ? AdminRun.GameIdOf(val) : null),
					LateJoin = PlayerInfo.LateJoinMod(actorNumber),
					GameTools = PlayerInfo.HasGameTools(actorNumber)
				});
			}
			return list;
		}

		private static Person Get(int actor)
		{
			List<Person> source = Everyone();
			return source.FirstOrDefault((Person p) => (actor != 0) ? (p.Actor == actor) : p.You) ?? source.FirstOrDefault((Person p) => p.You);
		}

		private static Person Me()
		{
			return Get(0);
		}

		internal static bool MayDisrupt(Person p, out string why)
		{
			why = null;
			if (p.You || Hosting)
			{
				return true;
			}
			if (p.Made != null)
			{
				if (p.Host || p.Mod)
				{
					why = (p.Host ? L.N("Not on the host.") : L.N("Not on other moderators."));
					return false;
				}
				return true;
			}
			return AdminHub.TargetAllowed(AdminHub.LocalActor, p.Actor, "kill", out why);
		}

		internal static List<string> RemoveChoices(Person p)
		{
			List<string> list = new List<string>();
			if (p.You)
			{
				return list;
			}
			bool num;
			if (p.Made == null)
			{
				num = Hub.CanTarget(p.Actor, out var _);
			}
			else
			{
				if (Hosting)
				{
					goto IL_0051;
				}
				if (p.Host || p.Mod)
				{
					goto IL_004f;
				}
				num = !p.Protected;
			}
			if (!num)
			{
				goto IL_004f;
			}
			goto IL_0051;
			IL_0051:
			if (Hosting || Hub.May(Caps.Kick))
			{
				list.Add("kick");
			}
			if (Hosting || Hub.May(Caps.Ban))
			{
				list.Add("ban");
			}
			if ((Hosting || Hub.May(Caps.BlockList)) && (p.Made != null || LateJoinPlus.Guard.Guard.IsSteamId(p.SteamId)))
			{
				list.Add("block");
			}
			return list;
			IL_004f:
			return list;
		}

		internal static void RemovePlayer(Person p, string how)
		{
			if (p.Made != null)
			{
				StatusOverlay.ShowNotice(L.T("Demo: nothing was sent."), 3f);
				return;
			}
			Hub.Remove(p.Actor, how, 0, out var message);
			string text = ((message != null) ? L.Remote(message) : L.T("Done."));
			if (IsOpen)
			{
				StatusOverlay.ShowNotice(text, 5f);
			}
			CallPhone.Banner(L.T("Admin Ctrl"), text, CallPhone.Tab.AdminCtrl, 0);
		}

		private static string HealthText(Person p)
		{
			if (!p.Present)
			{
				return "<color=#9a948c>" + L.T("loading") + "</color>";
			}
			if (p.Dead)
			{
				return "<color=#ff6154>" + L.T("Dead") + "</color>";
			}
			float num = ((p.MaxHp > 0) ? ((float)p.Hp / (float)p.MaxHp) : 0f);
			string text = ((num > 0.6f) ? "#73e673" : ((num > 0.3f) ? "#ff8f1f" : "#ff6154"));
			return "<color=" + text + ">" + p.Hp + "</color><color=#9a948c>/" + p.MaxHp + "</color>";
		}

		private static string Tags(Person p)
		{
			List<string> list = new List<string>();
			if (!p.You && p.Made == null && DevBadge.Is(p.Actor))
			{
				list.Add("<color=#28ff3c>DEV</color>");
			}
			if (p.Host)
			{
				list.Add("<color=#ffd94a>" + L.T("HOST") + "</color>");
			}
			else if (p.Mod)
			{
				list.Add("<color=#5ed6ff>" + L.T("MOD") + "</color>");
			}
			if (p.Protected)
			{
				list.Add("<color=#73e673>" + L.T("PROTECTED") + "</color>");
			}
			if (!string.IsNullOrEmpty(p.LateJoin))
			{
				list.Add("<color=#9a948c>" + PlayerInfo.ShortMod(p.LateJoin) + "</color>");
			}
			if (p.GameTools)
			{
				list.Add("<color=#9a948c>GT</color>");
			}
			return string.Join("  ", list);
		}

		internal static int PowerBits(Person p)
		{
			return AdminState.PowersOf((!string.IsNullOrEmpty(p.GameId)) ? p.GameId : (p.You ? Hub.LocalSteamId : p.SteamId));
		}

		internal static bool OwnGame(Person p)
		{
			if (!p.You)
			{
				if (p.Made == null)
				{
					return AdminHub.HasAdminFeatures(p.Actor);
				}
				return p.LateJoin == "LateJoinPlus";
			}
			return true;
		}

		private static void HomePage()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_046d: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: 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_0511: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: 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_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_071b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0832: Unknown result type (might be due to invalid IL or missing references)
			//IL_085d: Unknown result type (might be due to invalid IL or missing references)
			//IL_086c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0871: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f3: Unknown result type (might be due to invalid IL or missing references)
			float num = 318.66666f;
			float num2 = 200f;
			Person person = Me();
			Rect val = Ui.Card(R(236f, 84f, num, num2), L.T("You"));
			(int, string, string, string)[] powers;
			if (person != null)
			{
				int num3 = PowerBits(person);
				float num4 = (((Rect)(ref val)).width - 8f * S) / 2f;
				int num5 = 0;
				powers = AdminState.Powers;
				for (int i = 0; i < powers.Length; i++)
				{
					(int, string, string, string) tuple = powers[i];
					bool flag = (num3 & tuple.Item1) != 0;
					if (Chip(new Rect(((Rect)(ref val)).x + (float)(num5 % 2) * (num4 + 8f * S), ((Rect)(ref val)).y + (float)(num5 / 2) * 46f * S, num4, 40f * S), L.T(tuple.Item3), flag, "self:" + tuple.Item2))
					{
						Request("power", AdminHub.LocalActor, tuple.Item2, (!flag) ? 1 : 0);
					}
					num5++;
				}
				float num6 = ((Rect)(ref val)).y + 100f * S;
				if (Ui.Button(new Rect(((Rect)(ref val)).x, num6, num4, 40f * S), (person.Dead ? L.T("Revive") : L.T("Heal")).ToUpperInvariant(), Ui.Green, 14f, on: false, enabled: true, "self:heal"))
				{
					Request(person.Dead ? "revive" : "heal", AdminHub.LocalActor);
				}
				if (Ui.Button(new Rect(((Rect)(ref val)).x + num4 + 8f * S, num6, num4, 40f * S), L.T("Go to the truck").ToUpperInvariant(), Ui.Cyan, 14f, on: false, enabled: true, "self:truck"))
				{
					Request("truck", AdminHub.LocalActor);
				}
			}
			Rect val2 = Ui.Card(R(236f + num + 14f, 84f, num, num2), L.T("Everyone"));
			float num7 = (((Rect)(ref val2)).width - 8f * S) / 2f;
			(string, Color, string)[] array = new(string, Color, string)[4]
			{
				(L.T("HEAL EVERYONE"), Ui.Green, "healall"),
				(L.T("REVIVE EVERYONE"), Ui.Green, "reviveall"),
				(L.T("Bring everyone here").ToUpperInvariant(), Ui.Cyan, "bringall"),
				(L.T("Everyone to the truck").ToUpperInvariant(), Ui.Cyan, "truckall")
			};
			for (int j = 0; j < array.Length; j++)
			{
				(string, Color, string) tuple2 = array[j];
				if (Ui.Button(new Rect(((Rect)(ref val2)).x + (float)(j % 2) * (num7 + 8f * S), ((Rect)(ref val2)).y + (float)(j / 2) * 50f * S, num7, 42f * S), tuple2.Item1, tuple2.Item2, 13f, on: false, enabled: true, "everyone:" + tuple2.Item3))
				{
					Request(tuple2.Item3);
				}
			}
			if (!Hosting)
			{
				Ui.Label(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y + 104f * S, ((Rect)(ref val2)).width, 36f * S), Ui.Fit(L.T("Not on the host or other moderators."), 12f, ((Rect)(ref val2)).width), 12f, Ui.Muted, (TextAnchor)3);
			}
			Rect val3 = Ui.Card(R(236f + (num + 14f) * 2f, 84f, num, num2), L.T("Run"));
			int money = AdminRun.Money;
			int num8 = Shown("money", money);
			Ui.Label(new Rect(((Rect)(ref val3)).x, ((Rect)(ref val3)).y, 90f * S, 36f * S), "$" + num8 + "K", 18f, Ui.Yellow, (TextAnchor)3);
			int[] array2 = new int[3] { -10, 10, 100 };
			float num9 = ((Rect)(ref val3)).x + 92f * S;
			float num10 = (((Rect)(ref val3)).xMax - num9 - 12f * S) / 3f;
			for (int k = 0; k < array2.Length; k++)
			{
				if (Ui.Button(new Rect(num9 + (float)k * (num10 + 6f * S), ((Rect)(ref val3)).y, num10, 36f * S), ((array2[k] > 0) ? "+" : "") + array2[k] + "K", Ui.Yellow, 13f, on: false, enabled: true, "home-money" + array2[k]))
				{
					SetMoney(Mathf.Clamp(num8 + array2[k], 0, 9999), num8);
				}
			}
			if (Ui.Button(new Rect(((Rect)(ref val3)).x, ((Rect)(ref val3)).y + 46f * S, ((Rect)(ref val3)).width, 40f * S), L.T("Open the next extraction point").ToUpperInvariant(), Ui.Cyan, 13f, on: false, enabled: true, "home-extract.open"))
			{
				Request("extract.open");
			}
			if (Ui.Button(new Rect(((Rect)(ref val3)).x, ((Rect)(ref val3)).y + 94f * S, ((Rect)(ref val3)).width, 40f * S), Sure("home-extract.done") ? L.T("Sure?").ToUpperInvariant() : L.T("Finish this extraction").ToUpperInvariant(), Ui.Orange, 13f, Sure("home-extract.done"), enabled: true, "home-extract.done") && Confirm("home-extract.done"))
			{
				Request("extract.done");
			}
			float num11 = 84f + num2 + 14f;
			float num12 = 60f + (float)((AdminState.World.Length + 3) / 4) * 48f;
			float num13 = 656f - num2 - 28f - num12;
			Rect val4 = Ui.Card(R(236f, num11, 984f, num13), L.T("Quick spawn"));
			SpawnBar(new Rect(((Rect)(ref val4)).x, ((Rect)(ref val4)).y, ((Rect)(ref val4)).width, 40f * S), quick: true);
			string text = (Find ?? "").Trim();
			List<Spawnable> list = ((text.Length <= 0) ? Favourites().Concat(Recent.Where((Spawnable r) => !IsFavourite(r))).ToList() : Filter(AllSpawnables(SpawnKind), text));
			if (list.Count == 0)
			{
				Ui.Paragraph(new Rect(((Rect)(ref val4)).x, ((Rect)(ref val4)).y + 52f * S, ((Rect)(ref val4)).width, 60f * S), (text.Length > 0) ? L.T("Nothing matches.") : L.T("Your favourites (★ on the Spawn page) and what you spawned last show here. Or just start typing to find anything."), 14f, Ui.Muted, (TextAnchor)0);
			}
			Grid(new Rect(((Rect)(ref val4)).x, ((Rect)(ref val4)).y + 50f * S, ((Rect)(ref val4)).width, ((Rect)(ref val4)).height - 50f * S), list, 4, 0, "quick");
			Rect val5 = Ui.Card(R(236f, num11 + num13 + 14f, 984f, num12), L.T("World"));
			float num14 = (((Rect)(ref val5)).width - 24f * S) / 4f;
			int num15 = 0;
			powers = AdminState.World;
			for (int i = 0; i < powers.Length; i++)
			{
				(int, string, string, string) tuple3 = powers[i];
				bool flag2 = WorldOn(tuple3.Item1);
				if (Chip(new Rect(((Rect)(ref val5)).x + (float)(num15 % 4) * (num14 + 8f * S), ((Rect)(ref val5)).y + (float)(num15 / 4) * 48f * S, num14, 40f * S), L.T(tuple3.Item3), flag2, "world:" + tuple3.Item2))
				{
					Request("world", 0, tuple3.Item2, (!flag2) ? 1 : 0);
				}
				num15++;
			}
		}

		private static bool Chip(Rect r, string label, bool on, string spot)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			string text = (on ? "● " : "○ ") + label;
			float num = 13f;
			while (num > 10.5f && Ui.Width(text, num, bold: true) > ((Rect)(ref r)).width - 10f * S)
			{
				num -= 0.5f;
			}
			return Ui.Button(r, text, on ? Ui.Green : Ui.Muted, num, on, enabled: true, spot);
		}

		private static bool WorldOn(int bit)
		{
			return (AdminState.WorldBits & bit) != 0;
		}

		private static void SetMoney(int value, int shown)
		{
			if (value != shown)
			{
				Held["money"] = (value, Time.unscaledTime + 3f);
				AdminHub.RequestSoon("money", "money", 0, "", value);
			}
		}

		private static void LobbyPage()
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: 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_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0668: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_047f: 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_04ef: 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_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
			List<Person> list = Everyone();
			Room currentRoom = PhotonNetwork.CurrentRoom;
			int num = ((currentRoom != null) ? currentRoom.MaxPlayers : 0);
			int num2 = list.Count((Person p) => p.Present && !p.Dead);
			int num3 = list.Count((Person p) => p.Present && p.Dead);
			int num4 = list.Count((Person p) => !p.Present);
			Rect val = Ui.Card(R(236f, 84f, 984f, 656f), L.T("Players") + "  " + list.Count + ((num > 0) ? ("/" + num) : ""));
			Ui.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y - 30f * S, ((Rect)(ref val)).width, 22f * S), "<color=#73e673>●</color> " + L.F("{0} alive", num2) + "    <color=#ff6154>●</color> " + L.F("{0} dead", num3) + "    <color=#9a948c>●</color> " + L.F("{0} loading", num4), 13f, Ui.Muted, (TextAnchor)5);
			float num5 = ((Rect)(ref val)).width * 0.36f;
			float num6 = ((Rect)(ref val)).x + num5 + 10f * S;
			float num7 = ((Rect)(ref val)).width * 0.13f;
			float num8 = num6 + num7 + 10f * S;
			float num9 = ((Rect)(ref val)).width * 0.22f;
			float num10 = num8 + num9 + 16f * S;
			float y = ((Rect)(ref val)).y;
			Ui.Label(new Rect(((Rect)(ref val)).x + 10f * S, y, num5, 22f * S), L.T("PLAYER"), 12f, Ui.Muted, (TextAnchor)3);
			Ui.Label(new Rect(num6, y, num7, 22f * S), L.T("STATUS"), 12f, Ui.Muted, (TextAnchor)3);
			Ui.Label(new Rect(num8, y, num9, 22f * S), L.T("VOLUME"), 12f, Ui.Muted, (TextAnchor)3);
			Ui.Label(new Rect(num10, y, ((Rect)(ref val)).xMax - num10, 22f * S), L.T("REMOVE (CLICK TWICE)"), 12f, Ui.Muted, (TextAnchor)3);
			_lobbyPage = Mathf.Clamp(_lobbyPage, 0, Math.Max(0, (list.Count - 1) / 10));
			float num11 = y + 26f * S;
			Rect r = default(Rect);
			Rect val2 = default(Rect);
			for (int num12 = _lobbyPage * 10; num12 < list.Count && num12 < (_lobbyPage + 1) * 10; num12++)
			{
				Person person = list[num12];
				((Rect)(ref r))..ctor(((Rect)(ref val)).x, num11, ((Rect)(ref val)).width, 46f * S);
				Ui.Panel(r, new Color(1f, 1f, 1f, Ui.Hover(r) ? 0.07f : ((num12 % 2 == 0) ? 0.035f : 0.015f)), null, 7f);
				((Rect)(ref val2))..ctor(((Rect)(ref val)).x, num11, num5, ((Rect)(ref r)).height);
				string text = Tags(person);
				float num13 = num5 - 16f * S - ((text.Length > 0) ? (Ui.Width(Regex.Replace(text, "</?color[^>]*>", ""), 12f) + 10f * S) : 0f);
				Ui.Label(new Rect(((Rect)(ref val)).x + 10f * S, num11, num13, ((Rect)(ref r)).height), Ui.Fit(person.Name, 16f, Mathf.Max(60f * S, num13)), 16f, person.You ? Ui.Yellow : Ui.Text, (TextAnchor)3);
				if (text.Length > 0)
				{
					Ui.Label(new Rect(((Rect)(ref val)).x + 10f * S, num11, num5 - 14f * S, ((Rect)(ref r)).height), text, 12f, Ui.Muted, (TextAnchor)5);
				}
				Ui.Spots["lobby:" + person.Name] = val2;
				if (GUI.Button(val2, GUIContent.none, GUIStyle.none) || Ui.FakeClick(val2))
				{
					Ui.Click();
					Ui.LastClicked = "lobby:" + person.Name;
					Selected = ((!person.You) ? person.Actor : 0);
					Show(Page.Players);
				}
				Ui.Label(new Rect(num6, num11, num7, ((Rect)(ref r)).height), "● " + HealthText(person), 15f, Ui.Text, (TextAnchor)3);
				if (!person.You && (LateJoinPlus.Guard.Guard.IsSteamId(person.SteamId) || person.Made != null))
				{
					Volume(new Rect(num8, num11 + 9f * S, num9, 28f * S), person);
				}
				RemoveButtons(new Rect(num10, num11 + 8f * S, ((Rect)(ref val)).xMax - num10 - 6f * S, 30f * S), person, "");
				num11 += 50f * S;
			}
			Pager(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).yMax - 40f * S, ((Rect)(ref val)).width, 40f * S), ref _lobbyPage, list.Count, 10, "lobby");
		}

		private static void Volume(Rect r, Person p)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: 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_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			int num = ((p.Made == null) ? PlayerVolume.Percent(p.SteamId) : ((p.Actor % 3 == 0) ? 75 : 100));
			float height = ((Rect)(ref r)).height;
			int num2 = -1;
			if (Ui.Button(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, height, height), "<", Ui.Yellow, 14f, on: false, enabled: true, "vol-:" + p.Name))
			{
				num2 = num - 25;
			}
			if (Ui.Button(new Rect(((Rect)(ref r)).xMax - height, ((Rect)(ref r)).y, height, height), ">", Ui.Yellow, 14f, on: false, enabled: true, "vol+:" + p.Name))
			{
				num2 = num + 25;
			}
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref r)).x + height + 4f * S, ((Rect)(ref r)).y, ((Rect)(ref r)).width - 2f * height - 8f * S, height);
			float num3 = ((p.Made != null) ? 0f : CallVoice.Level(p.Actor));
			bool flag = num3 > 0.06f;
			Ui.Panel(val, new Color(0.08f, 0.08f, 0.1f, 0.9f), flag ? Ui.Alpha(Ui.Green, 0.95f) : Ui.Alpha(Ui.Yellow, 0.5f), 5f, flag ? 2f : 1f);
			float num4 = 2f * S;
			float num5 = Mathf.Clamp01((float)num / 200f);
			if (num5 > 0f)
			{
				Ui.Panel(new Rect(((Rect)(ref val)).x + num4, ((Rect)(ref val)).y + num4, (((Rect)(ref val)).width - num4 * 2f) * num5, ((Rect)(ref val)).height - num4 * 2f), Ui.Alpha(Ui.Orange, 0.85f), null, 4f);
			}
			Ui.Line(new Rect(((Rect)(ref val)).x + ((Rect)(ref val)).width * 0.5f, ((Rect)(ref val)).y + num4, Mathf.Max(1f, S), ((Rect)(ref val)).height - num4 * 2f), new Color(1f, 1f, 1f, 0.3f));
			if (num3 > 0.01f)
			{
				Ui.Panel(new Rect(((Rect)(ref val)).x + num4, ((Rect)(ref val)).y + num4, (((Rect)(ref val)).width - num4 * 2f) * Mathf.Clamp01(num3), ((Rect)(ref val)).height - num4 * 2f), new Color(0.6f, 1f, 0.65f, 0.45f), null, 4f);
			}
			Ui.Label(val, num + "%", 13f, Ui.Text, (TextAnchor)4, bold: true);
			if (GUI.Button(val, GUIContent.none, GUIStyle.none))
			{
				num2 = Mathf.RoundToInt(Mathf.Clamp01((Event.current.mousePosition.x - ((Rect)(ref val)).x) / ((Rect)(ref val)).width) * 8f) * 25;
				Ui.Click();
			}
			if (num2 >= 0 && p.Made == null)
			{
				PlayerVolume.Set(p.Actor, p.SteamId, Mathf.Clamp(num2, 0, 200) + "%");
			}
		}

		private static void RemoveButtons(Rect r, Person p, string spotPrefix)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if (p.You)
			{
				return;
			}
			List<string> list = RemoveChoices(p);
			if (list.Count == 0)
			{
				Ui.Label(r, p.Host ? L.T("HOST") : L.T("can't be removed"), 13f, Ui.Muted, (TextAnchor)3);
				return;
			}
			float num = 6f * S;
			float num2 = Mathf.Min(96f * S, (((Rect)(ref r)).width - num * 2f) / 3f);
			float num3 = ((Rect)(ref r)).x;
			foreach (string item in list)
			{
				string what = item + ":" + p.Actor;
				string text = (Sure(what) ? L.T("Sure?") : ((item == "kick") ? L.T("Kick") : ((item == "ban") ? L.T("Ban") : L.T("Block"))));
				if (Ui.Button(new Rect(num3, ((Rect)(ref r)).y, num2, ((Rect)(ref r)).height), text.ToUpperInvariant(), (item == "kick") ? Ui.Orange : Ui.Red, 13f, Sure(what), enabled: true, spotPrefix + item + ":" + p.Name) && Confirm(what))
				{
					RemovePlayer(p, item);
				}
				num3 += num2 + num;
			}
		}

		private static void PlayersPage()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0352: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_042c: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			List<Person> list = Everyone();
			Person person = Get(Selected);
			float num = 320f;
			Rect val = Ui.Card(R(236f, 84f, num, 656f), L.T("Players"));
			_playersPage = Mathf.Clamp(_playersPage, 0, Math.Max(0, (list.Count - 1) / 10));
			float num2 = ((Rect)(ref val)).y;
			Rect val2 = default(Rect);
			for (int i = _playersPage * 10; i < list.Count && i < (_playersPage + 1) * 10; i++)
			{
				Person person2 = list[i];
				((Rect)(ref val2))..ctor(((Rect)(ref val)).x, num2, ((Rect)(ref val)).width, 44f * S);
				bool flag = person != null && person2.Actor == person.Actor;
				Ui.Panel(val2, (Color)(flag ? Ui.Alpha(Ui.Yellow, 0.16f) : new Color(1f, 1f, 1f, Ui.Hover(val2) ? 0.07f : 0.025f)), flag ? new Color?(Ui.Alpha(Ui.Yellow, 0.6f)) : ((Color?)null), 7f, 1f);
				float num3 = 76f * S;
				Ui.Label(new Rect(((Rect)(ref val2)).x + 10f * S, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width - num3 - 20f * S, ((Rect)(ref val2)).height), Ui.Fit(person2.Name, 16f, ((Rect)(ref val2)).width - num3 - 20f * S), 16f, flag ? Ui.Yellow : Ui.Text, (TextAnchor)3);
				Ui.Label(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).y, ((Rect)(ref val2)).width - 10f * S, ((Rect)(ref val2)).height), HealthText(person2), 14f, Ui.Text, (TextAnchor)5);
				string text = "player:" + person2.Name;
				Ui.Spots[text] = val2;
				if (GUI.Button(val2, GUIContent.none, GUIStyle.none) || Ui.FakeClick(val2))
				{
					Ui.Click();
					Ui.LastClicked = text;
					Sele

patchers/LateJoinPlus.MenuLibCompatibility.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LateJoinPlus.Compatibility
{
	public static class MenuLibClickShim
	{
		private static bool _checked;

		public static IEnumerable<string> TargetDLLs => new string[1] { "Assembly-CSharp.dll" };

		public static void Patch(AssemblyDefinition assembly)
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Expected O, but got Unknown
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Expected O, but got Unknown
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			if (_checked)
			{
				return;
			}
			_checked = true;
			ManualLogSource val = null;
			try
			{
				val = Logger.CreateLogSource("LateJoinPlus MenuLib compatibility");
				TypeDefinition type = assembly.MainModule.GetType("MenuManager");
				if (type == null || ((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => IsClick((MethodReference)(object)m, 5)))
				{
					return;
				}
				MethodDefinition val2 = ((IEnumerable<MethodDefinition>)type.Methods).SingleOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => IsClick((MethodReference)(object)m, 6)));
				if (val2 == null || !val2.IsPublic)
				{
					return;
				}
				SortedSet<string> sortedSet = new SortedSet<string>();
				if (!Directory.Exists(Paths.PluginPath))
				{
					return;
				}
				foreach (string item in Directory.EnumerateFiles(Paths.PluginPath, "MenuLib.dll", SearchOption.AllDirectories))
				{
					AssemblyDefinition val3 = AssemblyDefinition.ReadAssembly(item);
					try
					{
						if (((AssemblyNameReference)val3.Name).Name != "MenuLib")
						{
							continue;
						}
						Enumerator<ModuleDefinition> enumerator2 = val3.Modules.GetEnumerator();
						try
						{
							while (enumerator2.MoveNext())
							{
								foreach (TypeDefinition item2 in AllTypes((IEnumerable<TypeDefinition>)enumerator2.Current.Types))
								{
									Enumerator<MethodDefinition> enumerator4 = item2.Methods.GetEnumerator();
									try
									{
										while (enumerator4.MoveNext())
										{
											MethodDefinition current2 = enumerator4.Current;
											if (current2.HasBody && ((IEnumerable<Instruction>)current2.Body.Instructions).Any(IsOldCall))
											{
												sortedSet.Add(((MemberReference)item2).FullName + "." + ((MemberReference)current2).Name);
											}
										}
									}
									finally
									{
										((IDisposable)enumerator4/*cast due to .constrained prefix*/).Dispose();
									}
								}
							}
						}
						finally
						{
							((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
						}
					}
					finally
					{
						((IDisposable)val3)?.Dispose();
					}
				}
				if (sortedSet.Count == 0)
				{
					return;
				}
				MethodDefinition val4 = new MethodDefinition("MenuEffectClick", (MethodAttributes)134, assembly.MainModule.TypeSystem.Void);
				foreach (ParameterDefinition item3 in ((IEnumerable<ParameterDefinition>)((MethodReference)val2).Parameters).Take(5))
				{
					((MethodReference)val4).Parameters.Add(new ParameterDefinition(((ParameterReference)item3).Name, (ParameterAttributes)0, ((ParameterReference)item3).ParameterType));
				}
				ILProcessor iLProcessor = val4.Body.GetILProcessor();
				iLProcessor.Emit(OpCodes.Ldarg_0);
				Enumerator<ParameterDefinition> enumerator6 = ((MethodReference)val4).Parameters.GetEnumerator();
				try
				{
					while (enumerator6.MoveNext())
					{
						ParameterDefinition current4 = enumerator6.Current;
						iLProcessor.Emit(OpCodes.Ldarg, current4);
					}
				}
				finally
				{
					((IDisposable)enumerator6/*cast due to .constrained prefix*/).Dispose();
				}
				iLProcessor.Emit(OpCodes.Ldc_I4_0);
				iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val2);
				iLProcessor.Emit(OpCodes.Ret);
				val4.Body.MaxStackSize = 7;
				type.Methods.Add(val4);
				val.LogInfo((object)("Added the five-argument MenuEffectClick bridge (rumble=false) for: " + string.Join(", ", sortedSet) + "."));
			}
			catch (Exception ex)
			{
				if (val != null)
				{
					val.LogWarning((object)("MenuLib click compatibility could not be applied: " + ex));
				}
			}
			finally
			{
				if (val != null)
				{
					val.Dispose();
				}
			}
		}

		private static bool IsOldCall(Instruction instruction)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (instruction.OpCode == OpCodes.Call || instruction.OpCode == OpCodes.Callvirt)
			{
				object operand = instruction.Operand;
				MethodReference val = (MethodReference)((operand is MethodReference) ? operand : null);
				if (val != null)
				{
					IMetadataScope scope = ((MemberReference)val).DeclaringType.Scope;
					AssemblyNameReference val2 = (AssemblyNameReference)(object)((scope is AssemblyNameReference) ? scope : null);
					if (val2 != null && val2.Name == "Assembly-CSharp")
					{
						return IsClick(val, 5);
					}
				}
			}
			return false;
		}

		private static bool IsClick(MethodReference method, int count)
		{
			if (((MemberReference)method).Name != "MenuEffectClick" || ((MemberReference)((MemberReference)method).DeclaringType).FullName != "MenuManager" || !method.HasThis || method.ExplicitThis || method.HasGenericParameters || ((MemberReference)method.ReturnType).FullName != "System.Void" || method.Parameters.Count != count)
			{
				return false;
			}
			string[] array = new string[6] { "MenuManager/MenuClickEffectType", "MenuPage", "System.Single", "System.Single", "System.Boolean", "System.Boolean" };
			for (int i = 0; i < count; i++)
			{
				if (((MemberReference)((ParameterReference)method.Parameters[i]).ParameterType).FullName != array[i])
				{
					return false;
				}
			}
			return true;
		}

		private static IEnumerable<TypeDefinition> AllTypes(IEnumerable<TypeDefinition> types)
		{
			foreach (TypeDefinition type in types)
			{
				yield return type;
				foreach (TypeDefinition item in AllTypes((IEnumerable<TypeDefinition>)type.NestedTypes))
				{
					yield return item;
				}
			}
		}
	}
	public static class SharePermissionsChoice
	{
		internal const string DataKey = "RicketyWrecked.LJP.SPMode";

		internal const string SpGuid = "RED.SharePermissions";

		internal const string TableKey = "RicketyWrecked.LJP.Conflicts";

		internal const string ModePrefix = "RicketyWrecked.LJP.Conflict.";

		internal static readonly string[][] Listed = new string[2][]
		{
			new string[6] { "RED.SharePermissions", "SharePermissions", "SharePermissions", "sp.what", "restart", "sp.technical" },
			new string[6] { "y_meny_IJJu3a.Casino", "RepoCasino", "RepoCasino", "casino.what", "casino.why", "casino.technical" }
		};

		private static readonly HashSet<string> Blocked = new HashSet<string>(StringComparer.OrdinalIgnoreCase);

		private static ManualLogSource _log;

		private static bool _started;

		private static bool _blocking;

		private static bool _warned;

		private static bool _announced;

		public static IEnumerable<string> TargetDLLs => new string[0];

		public static void Patch(AssemblyDefinition assembly)
		{
		}

		public static void Initialize()
		{
			if (_started)
			{
				return;
			}
			_started = true;
			Blocked.Clear();
			AppDomain.CurrentDomain.SetData("RicketyWrecked.LJP.Conflicts", Listed);
			try
			{
				_log = Logger.CreateLogSource("LateJoinPlus mod choice");
				string path = Path.Combine(Paths.ConfigPath, "ricketywrecked.repo.latejoinplus.cfg");
				bool clean;
				HashSet<string> hashSet = FindConflicts(Paths.PluginPath, out clean);
				bool flag = false;
				string[][] listed = Listed;
				foreach (string[] array in listed)
				{
					string text = array[2];
					string text2 = ReadMode(path, text);
					bool flag2 = hashSet.Contains(array[0]);
					if (!flag2 && clean && text2 == "KeepOther")
					{
						ResetMissingChoice(path, text);
					}
					if (!flag2 && !clean && text2 == "KeepOther")
					{
						flag2 = true;
					}
					AppDomain.CurrentDomain.SetData("RicketyWrecked.LJP.Conflict." + text, flag2 ? text2 : "None");
					if (array[0] == "RED.SharePermissions")
					{
						AppDomain.CurrentDomain.SetData("RicketyWrecked.LJP.SPMode", (!flag2) ? "None" : ((text2 == "KeepOther") ? "KeepSharePermissions" : text2));
					}
					if (text2 != "KeepOther" && (flag2 || !clean))
					{
						Blocked.Add(array[0]);
					}
					if (text2 == "KeepOther" && flag2)
					{
						flag = true;
					}
				}
				if (flag)
				{
					Blocked.Clear();
				}
				_blocking = Blocked.Count > 0;
			}
			catch (Exception e)
			{
				_blocking = false;
				Warn(e);
			}
		}

		public static void Finish()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			if (!_blocking)
			{
				return;
			}
			try
			{
				new Harmony("ricketywrecked.repo.latejoinplus.spchoice").Patch((MethodBase)typeof(Chainloader).GetMethod("Start", BindingFlags.Static | BindingFlags.Public), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(SharePermissionsChoice), "InsertFilter", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception e)
			{
				_blocking = false;
				Warn(e);
			}
		}

		private static void Warn(Exception e)
		{
			if (_warned)
			{
				return;
			}
			_warned = true;
			try
			{
				ManualLogSource log = _log;
				if (log != null)
				{
					log.LogWarning((object)("Conflicting mod load choice failed; leaving plugin loading unchanged (" + e.GetType().Name + ")."));
				}
			}
			catch
			{
			}
		}

		internal static string ReadMode(string path, string key)
		{
			if (!File.Exists(path))
			{
				return "Ask";
			}
			string text = "";
			string result = "Ask";
			string[] array = File.ReadAllLines(path);
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (text2.StartsWith("#", StringComparison.Ordinal))
				{
					continue;
				}
				if (text2.StartsWith("[", StringComparison.Ordinal) && text2.EndsWith("]", StringComparison.Ordinal))
				{
					text = text2.Substring(1, text2.Length - 2);
					continue;
				}
				int num = text2.IndexOf('=');
				if (!(text != "Mod conflicts") && num >= 0 && !(text2.Substring(0, num).Trim() != key))
				{
					string text3 = text2.Substring(num + 1).Trim();
					result = ((text3 == "KeepOther" || text3 == "Keep" + key) ? "KeepOther" : ((text3 == "KeepLateJoinPlus") ? text3 : "Ask"));
				}
			}
			return result;
		}

		internal static void ResetMissingChoice(string path, string key)
		{
			string[] array = File.ReadAllLines(path);
			string text = "";
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim();
				if (!text2.StartsWith("#", StringComparison.Ordinal))
				{
					if (text2.StartsWith("[", StringComparison.Ordinal) && text2.EndsWith("]", StringComparison.Ordinal))
					{
						text = text2.Substring(1, text2.Length - 2);
					}
					int num = text2.IndexOf('=');
					if (text == "Mod conflicts" && num >= 0 && text2.Substring(0, num).Trim() == key)
					{
						array[i] = key + " = Ask";
					}
				}
			}
			File.WriteAllLines(path, array, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
		}

		internal static HashSet<string> FindConflicts(string directory, out bool clean)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			clean = true;
			if (!Directory.Exists(directory))
			{
				return hashSet;
			}
			foreach (string item in DllFiles(directory, ref clean))
			{
				try
				{
					AssemblyDefinition val = AssemblyDefinition.ReadAssembly(item);
					try
					{
						if (!((IEnumerable<AssemblyNameReference>)val.MainModule.AssemblyReferences).Any((AssemblyNameReference r) => r.Name == "BepInEx"))
						{
							continue;
						}
						foreach (CustomAttribute item2 in Types((IEnumerable<TypeDefinition>)val.MainModule.Types).SelectMany((TypeDefinition t) => (IEnumerable<CustomAttribute>)t.CustomAttributes))
						{
							if (((MemberReference)item2.AttributeType).FullName == "BepInEx.BepInPlugin" && item2.ConstructorArguments.Count == 3)
							{
								CustomAttributeArgument val2 = item2.ConstructorArguments[0];
								string guid = ((CustomAttributeArgument)(ref val2)).Value as string;
								if (Listed.Any((string[] e) => string.Equals(e[0], guid, StringComparison.OrdinalIgnoreCase)))
								{
									hashSet.Add(guid);
								}
							}
						}
					}
					finally
					{
						((IDisposable)val)?.Dispose();
					}
				}
				catch (Exception)
				{
				}
			}
			return hashSet;
		}

		private static List<string> DllFiles(string root, ref bool clean)
		{
			List<string> list = new List<string>();
			Stack<string> stack = new Stack<string>();
			stack.Push(root);
			while (stack.Count > 0)
			{
				string path = stack.Pop();
				try
				{
					list.AddRange(Directory.GetFiles(path, "*.dll"));
					string[] directories = Directory.GetDirectories(path);
					foreach (string item in directories)
					{
						stack.Push(item);
					}
				}
				catch (Exception)
				{
					clean = false;
				}
			}
			return list;
		}

		private static IEnumerable<TypeDefinition> Types(IEnumerable<TypeDefinition> roots)
		{
			foreach (TypeDefinition type in roots)
			{
				yield return type;
				foreach (TypeDefinition item in Types((IEnumerable<TypeDefinition>)type.NestedTypes))
				{
					yield return item;
				}
			}
		}

		private static IEnumerable<CodeInstruction> InsertFilter(IEnumerable<CodeInstruction> instructions)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			List<CodeInstruction> list = instructions.ToList();
			try
			{
				CodeInstruction[] array = list.Where((CodeInstruction i) => (i.opcode == OpCodes.Call || i.opcode == OpCodes.Callvirt) && i.operand is MethodInfo methodInfo && methodInfo.DeclaringType == typeof(TypeLoader) && methodInfo.Name == "FindPluginTypes" && methodInfo.IsGenericMethod && methodInfo.GetGenericArguments().SequenceEqual(new Type[1] { typeof(PluginInfo) })).ToArray();
				if (array.Length != 1)
				{
					throw new InvalidOperationException("Chainloader plugin lookup changed");
				}
				list.Insert(list.IndexOf(array[0]) + 1, new CodeInstruction(OpCodes.Call, (object)typeof(SharePermissionsChoice).GetMethod("FilterPlugins", BindingFlags.Static | BindingFlags.NonPublic)));
			}
			catch (Exception e)
			{
				_blocking = false;
				Warn(e);
			}
			return list;
		}

		private static Dictionary<string, List<PluginInfo>> FilterPlugins(Dictionary<string, List<PluginInfo>> plugins)
		{
			if (!_blocking)
			{
				return plugins;
			}
			try
			{
				Dictionary<string, List<PluginInfo>> dictionary = new Dictionary<string, List<PluginInfo>>(plugins.Comparer);
				int num = 0;
				foreach (KeyValuePair<string, List<PluginInfo>> plugin in plugins)
				{
					List<PluginInfo> list = new List<PluginInfo>();
					foreach (PluginInfo item in plugin.Value)
					{
						if (Blocked.Contains(item.Metadata.GUID))
						{
							num++;
						}
						else
						{
							list.Add(item);
						}
					}
					dictionary.Add(plugin.Key, list);
				}
				if (num == 0)
				{
					return plugins;
				}
				if (!_announced)
				{
					_log.LogInfo((object)("Conflicting mods held back by the load choice: " + string.Join(", ", from array in Listed
						where Blocked.Contains(array[0])
						select array[1]) + ". Change it in LateJoinPlus settings."));
					_announced = true;
				}
				return dictionary;
			}
			catch (Exception e)
			{
				_blocking = false;
				Warn(e);
				return plugins;
			}
		}
	}
}