Decompiled source of ACNPlus v1.2.1

ACNPlus.dll

Decompiled 20 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using ACNPlus.MinimapReplacement;
using BepInEx;
using BepInEx.Configuration;
using BombRushMP.Common.Networking;
using BombRushMP.Common.Packets;
using BombRushMP.Plugin;
using HarmonyLib;
using Reptile;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("ACNPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ACNPlus")]
[assembly: AssemblyTitle("ACNPlus")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ACNPlus
{
	[BepInPlugin("com.acn.acnplus", "ACNPlus", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ACNPlusPlugin : BaseUnityPlugin
	{
		private static Harmony _harmony;

		private static string _acnPlusFolder;

		private static string _friendsListPath;

		private static string _blocklistPath;

		private static HashSet<string> _friendsList = new HashSet<string>();

		private static HashSet<string> _blocklist = new HashSet<string>();

		public static ConfigEntry<bool> BlockInvites;

		public static ConfigEntry<bool> BlockInvitesChatMessage;

		public static ConfigEntry<bool> BlockPlayersFromJoiningLobby;

		public static ConfigEntry<bool> FriendsOnlyLobby;

		public static ConfigEntry<bool> CrewOnlyLobby;

		public static ConfigEntry<bool> SeeWhenSomethingIsBlocked;

		public static ConfigEntry<bool> ChangeMiniMapToPNG;

		public static ConfigEntry<bool> CatWizardMiniMap;

		public static ConfigEntry<bool> TransparentLobbyBanner;

		public static ConfigEntry<bool> TransparentLobbyNameBG;

		public static ConfigEntry<bool> HideLobbySettings;

		private static string _texturesFolder;

		private static string _pluginFolder;

		private void Awake()
		{
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Expected O, but got Unknown
			BlockInvites = ((BaseUnityPlugin)this).Config.Bind<bool>("Gamemodes", "BlockInvites", false, "Automatically decline all lobby invites");
			BlockInvitesChatMessage = ((BaseUnityPlugin)this).Config.Bind<bool>("Gamemodes", "BlockInvitesChatMessage", false, "Show a chat message when an invite is blocked");
			BlockPlayersFromJoiningLobby = ((BaseUnityPlugin)this).Config.Bind<bool>("Gamemodes", "BlockPlayersFromJoiningLobby", false, "Automatically kick players who join your lobby (only works if you are the host)");
			FriendsOnlyLobby = ((BaseUnityPlugin)this).Config.Bind<bool>("Gamemodes", "FriendsOnlyLobby", false, "Automatically kick players who aren't on your friends list (only works if you are the host)");
			CrewOnlyLobby = ((BaseUnityPlugin)this).Config.Bind<bool>("Gamemodes", "CrewOnlyLobby", false, "Automatically kick players who aren't in your crew (only works if you are the host)");
			SeeWhenSomethingIsBlocked = ((BaseUnityPlugin)this).Config.Bind<bool>("Blocked Users", "SeeWhenSomethingIsBlocked", true, "Show chat messages when blocked users send messages, invites, or get kicked");
			ChangeMiniMapToPNG = ((BaseUnityPlugin)this).Config.Bind<bool>("Minimap", "ChangeMiniMapToPNG", false, "Replace the minimap with a custom image from ACNPlus/Textures/MiniMapPNG.png");
			CatWizardMiniMap = ((BaseUnityPlugin)this).Config.Bind<bool>("Minimap", "CatWizardMiniMap", false, "An example of a custom mini map (uses backendtextures/CatMiniMap.png)");
			TransparentLobbyBanner = ((BaseUnityPlugin)this).Config.Bind<bool>("Lobby Banners", "TransparentLobbyBanner", false, "Use transparent image for lobby title background (from mod folder backendtextures/transparent.png)");
			TransparentLobbyNameBG = ((BaseUnityPlugin)this).Config.Bind<bool>("Lobby Banners", "TransparentLobbyNameBG", false, "Use transparent image for name row background in both normal and team mode (from mod folder backendtextures/transparent.png)");
			HideLobbySettings = ((BaseUnityPlugin)this).Config.Bind<bool>("Lobby UI", "HideLobbySettings", false, "Hide the game settings text beside the lobby UI when in a lobby");
			_pluginFolder = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			_acnPlusFolder = Path.Combine(Paths.BepInExRootPath, "ACNPlus");
			_texturesFolder = Path.Combine(_acnPlusFolder, "Textures");
			_friendsListPath = Path.Combine(_acnPlusFolder, "FriendsList.txt");
			_blocklistPath = Path.Combine(_acnPlusFolder, "blocklist.txt");
			Directory.CreateDirectory(_acnPlusFolder);
			Directory.CreateDirectory(_texturesFolder);
			if (!File.Exists(_friendsListPath))
			{
				File.WriteAllText(_friendsListPath, "");
			}
			if (!File.Exists(_blocklistPath))
			{
				File.WriteAllText(_blocklistPath, "");
			}
			LoadFriendsList();
			LoadBlocklist();
			_harmony = new Harmony("com.acn.acnplus");
			_harmony.PatchAll();
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private static void LoadFriendsList()
		{
			_friendsList.Clear();
			if (!File.Exists(_friendsListPath))
			{
				return;
			}
			string[] array = File.ReadAllLines(_friendsListPath);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (!string.IsNullOrEmpty(text))
				{
					_friendsList.Add(text);
				}
			}
		}

		private static void LoadBlocklist()
		{
			_blocklist.Clear();
			if (!File.Exists(_blocklistPath))
			{
				return;
			}
			string[] array = File.ReadAllLines(_blocklistPath);
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (!string.IsNullOrEmpty(text))
				{
					_blocklist.Add(text);
				}
			}
		}

		public static HashSet<string> GetFriendsList()
		{
			return _friendsList;
		}

		public static string GetFriendsFolder()
		{
			return _acnPlusFolder;
		}

		public static string GetTexturesFolder()
		{
			return _texturesFolder;
		}

		public static HashSet<string> GetBlocklist()
		{
			return _blocklist;
		}

		public static string GetBlocklistPath()
		{
			return _blocklistPath;
		}

		public static void ReloadBlocklist()
		{
			LoadBlocklist();
		}

		public static string GetPluginFolder()
		{
			return _pluginFolder;
		}

		public static string GetBackendTexturesPath(string filename)
		{
			return Path.Combine(_pluginFolder, "backendtextures", filename);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.acn.acnplus";

		public const string PLUGIN_NAME = "ACNPlus";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ACNPlus";

		public const string PLUGIN_NAME = "ACNPlus";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ACNPlus.Patches
{
	[HarmonyPatch(typeof(ChatUI), "HandleServerMessage")]
	public class BlocklistChatPatch
	{
		[HarmonyPrefix]
		public static bool HandleServerMessage_Prefix(ServerChat serverMessage)
		{
			if (serverMessage == null || string.IsNullOrEmpty(serverMessage.Author))
			{
				return true;
			}
			if (ACNPlusPlugin.GetBlocklist().Contains(serverMessage.Author))
			{
				if (ACNPlusPlugin.SeeWhenSomethingIsBlocked.Value)
				{
					ChatUI instance = ChatUI.Instance;
					if (instance != null)
					{
						instance.AddMessage("<color=red>Blocked message from " + serverMessage.Author + "</color>");
					}
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ChatUI), "ProcessLocalCommand")]
	public static class ChatCommandPatch
	{
		private static bool Prefix(ChatUI __instance, string message)
		{
			if (string.IsNullOrEmpty(message))
			{
				return true;
			}
			string[] array = message.Split(new char[1] { ' ' });
			switch (array[0].ToLower())
			{
			case "/addme":
				HandleAddMeCommand();
				return false;
			case "/addfriend":
				if (array.Length < 2)
				{
					ChatUI instance4 = ChatUI.Instance;
					if (instance4 != null)
					{
						instance4.AddMessage("<color=red>Usage: /addfriend <player_id></color>");
					}
					return false;
				}
				HandleAddFriendCommand(array[1]);
				return false;
			case "/friendslist":
				HandleFriendsListCommand();
				return false;
			case "/removefriend":
				if (array.Length < 2)
				{
					ChatUI instance3 = ChatUI.Instance;
					if (instance3 != null)
					{
						instance3.AddMessage("<color=red>Usage: /removefriend <number></color>");
					}
					return false;
				}
				HandleRemoveFriendCommand(array[1]);
				return false;
			case "/friends":
				HandleFriendsCommand();
				return false;
			case "/playershelp":
				HandlePlayersHelpCommand();
				return false;
			case "/acnplushelp":
				HandleACNPlusHelpCommand();
				return false;
			case "/friendguide":
				HandleFriendGuideCommand();
				return false;
			case "/crews":
				HandleCrewsCommand();
				return false;
			case "/mycrew":
				HandleMyCrewCommand();
				return false;
			case "/listplayers":
				HandleListPlayersCommand();
				return false;
			case "/block":
				if (array.Length < 2)
				{
					ChatUI instance2 = ChatUI.Instance;
					if (instance2 != null)
					{
						instance2.AddMessage("<color=red>Usage: /block <number></color>");
					}
					return false;
				}
				HandleBlockCommand(array[1]);
				return false;
			case "/unblock":
				if (array.Length < 2)
				{
					ChatUI instance = ChatUI.Instance;
					if (instance != null)
					{
						instance.AddMessage("<color=red>Usage: /unblock <number></color>");
					}
					return false;
				}
				HandleUnblockCommand(array[1]);
				return false;
			case "/blocklist":
				HandleBlocklistCommand();
				return false;
			default:
				return true;
			}
		}

		private static void HandleAddMeCommand()
		{
			ClientController instance = ClientController.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				ChatUI instance2 = ChatUI.Instance;
				if (instance2 != null)
				{
					instance2.AddMessage("<color=red>Not connected to server!</color>");
				}
				return;
			}
			ushort localID = instance.LocalID;
			ChatUI instance3 = ChatUI.Instance;
			if (instance3 != null)
			{
				instance3.AddMessage($"<color=green>Your Player ID: {localID}</color>");
			}
		}

		private static void HandleAddFriendCommand(string playerIdStr)
		{
			if (!ushort.TryParse(playerIdStr, out var result))
			{
				ChatUI instance = ChatUI.Instance;
				if (instance != null)
				{
					instance.AddMessage("<color=red>Invalid player ID! Must be a number.</color>");
				}
				return;
			}
			ClientController instance2 = ClientController.Instance;
			if ((Object)(object)instance2 == (Object)null)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage("<color=red>Not connected to server!</color>");
				}
				return;
			}
			if (result == instance2.LocalID)
			{
				ChatUI instance4 = ChatUI.Instance;
				if (instance4 != null)
				{
					instance4.AddMessage("<color=red>You cannot add yourself as a friend!</color>");
				}
				return;
			}
			if (!instance2.Players.TryGetValue(result, out var value) || value.ClientState == null)
			{
				ChatUI instance5 = ChatUI.Instance;
				if (instance5 != null)
				{
					instance5.AddMessage($"<color=red>Player with ID {result} not found!</color>");
				}
				return;
			}
			string name = value.ClientState.Name;
			HashSet<string> friendsList = ACNPlusPlugin.GetFriendsList();
			if (friendsList.Contains(name))
			{
				ChatUI instance6 = ChatUI.Instance;
				if (instance6 != null)
				{
					instance6.AddMessage("<color=yellow>" + name + " is already in your friends list!</color>");
				}
				return;
			}
			string path = Path.Combine(ACNPlusPlugin.GetFriendsFolder(), "FriendsList.txt");
			try
			{
				File.AppendAllText(path, name + Environment.NewLine);
				friendsList.Add(name);
				ChatUI instance7 = ChatUI.Instance;
				if (instance7 != null)
				{
					instance7.AddMessage("<color=green>Added " + name + " to your friends list!</color>");
				}
			}
			catch (Exception)
			{
				ChatUI instance8 = ChatUI.Instance;
				if (instance8 != null)
				{
					instance8.AddMessage("<color=red>Failed to save friend to list!</color>");
				}
			}
		}

		private static void HandleFriendsListCommand()
		{
			HashSet<string> friendsList = ACNPlusPlugin.GetFriendsList();
			if (friendsList.Count == 0)
			{
				ChatUI instance = ChatUI.Instance;
				if (instance != null)
				{
					instance.AddMessage("<color=yellow>Your friends list is empty!</color>");
				}
				ChatUI instance2 = ChatUI.Instance;
				if (instance2 != null)
				{
					instance2.AddMessage("<color=white>Use /addfriend <player_id> to add friends</color>");
				}
				return;
			}
			ChatUI instance3 = ChatUI.Instance;
			if (instance3 != null)
			{
				instance3.AddMessage("<color=green>=== Friends List ===</color>");
			}
			string[] array = friendsList.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				ChatUI instance4 = ChatUI.Instance;
				if (instance4 != null)
				{
					instance4.AddMessage($"<color=white>{i + 1}. {array[i]}</color>");
				}
			}
			ChatUI instance5 = ChatUI.Instance;
			if (instance5 != null)
			{
				instance5.AddMessage($"<color=green>Total: {friendsList.Count} friends</color>");
			}
		}

		private static void HandleRemoveFriendCommand(string numberStr)
		{
			if (!int.TryParse(numberStr, out var result) || result < 1)
			{
				ChatUI instance = ChatUI.Instance;
				if (instance != null)
				{
					instance.AddMessage("<color=red>Invalid number! Must be a positive number.</color>");
				}
				return;
			}
			HashSet<string> friendsList = ACNPlusPlugin.GetFriendsList();
			if (friendsList.Count == 0)
			{
				ChatUI instance2 = ChatUI.Instance;
				if (instance2 != null)
				{
					instance2.AddMessage("<color=yellow>Your friends list is empty!</color>");
				}
				return;
			}
			if (result > friendsList.Count)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage($"<color=red>Invalid number! You only have {friendsList.Count} friends.</color>");
				}
				return;
			}
			string text = friendsList.ToArray()[result - 1];
			string path = Path.Combine(ACNPlusPlugin.GetFriendsFolder(), "FriendsList.txt");
			try
			{
				friendsList.Remove(text);
				File.WriteAllLines(path, friendsList);
				ChatUI instance4 = ChatUI.Instance;
				if (instance4 != null)
				{
					instance4.AddMessage("<color=green>Removed " + text + " from your friends list!</color>");
				}
			}
			catch (Exception)
			{
				ChatUI instance5 = ChatUI.Instance;
				if (instance5 != null)
				{
					instance5.AddMessage("<color=red>Failed to remove friend from list!</color>");
				}
			}
		}

		private static void HandleFriendsCommand()
		{
			HashSet<string> friendsList = ACNPlusPlugin.GetFriendsList();
			if (friendsList.Count == 0)
			{
				ChatUI instance = ChatUI.Instance;
				if (instance != null)
				{
					instance.AddMessage("<color=yellow>Your friends list is empty!</color>");
				}
				return;
			}
			ClientController instance2 = ClientController.Instance;
			if ((Object)(object)instance2 == (Object)null)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage("<color=red>Not connected to server!</color>");
				}
				return;
			}
			ClientLobbyManager clientLobbyManager = instance2.ClientLobbyManager;
			List<string> list = new List<string>();
			List<string> list2 = new List<string>();
			foreach (MPPlayer value in instance2.Players.Values)
			{
				if (value.ClientState == null)
				{
					continue;
				}
				string name = value.ClientState.Name;
				if (!friendsList.Contains(name))
				{
					continue;
				}
				list.Add(name);
				foreach (Lobby value2 in clientLobbyManager.Lobbies.Values)
				{
					if (value2.LobbyState.Players.ContainsKey(value.ClientId))
					{
						if (value2.LobbyState.InGame)
						{
							list2.Add(name);
						}
						break;
					}
				}
			}
			if (list.Count > 0)
			{
				string text = "<color=green>Friends Online: " + string.Join(", ", list) + "</color>";
				ChatUI instance4 = ChatUI.Instance;
				if (instance4 != null)
				{
					instance4.AddMessage(text);
				}
				if (list2.Count > 0)
				{
					string text2 = "<color=yellow>In Game: " + string.Join(", ", list2) + "</color>";
					ChatUI instance5 = ChatUI.Instance;
					if (instance5 != null)
					{
						instance5.AddMessage(text2);
					}
				}
			}
			else
			{
				ChatUI instance6 = ChatUI.Instance;
				if (instance6 != null)
				{
					instance6.AddMessage("<color=yellow>No friends are currently online.</color>");
				}
			}
		}

		private static void HandlePlayersHelpCommand()
		{
			ChatUI instance = ChatUI.Instance;
			if (instance != null)
			{
				instance.AddMessage("<color=green>=== ACNPlus Commands ===</color>");
			}
			ChatUI instance2 = ChatUI.Instance;
			if (instance2 != null)
			{
				instance2.AddMessage("<color=white>/addme - Display your player ID</color>");
			}
			ChatUI instance3 = ChatUI.Instance;
			if (instance3 != null)
			{
				instance3.AddMessage("<color=white>/addfriend <id> - Add a friend (e.g., /addfriend 51)</color>");
			}
			ChatUI instance4 = ChatUI.Instance;
			if (instance4 != null)
			{
				instance4.AddMessage("<color=white>/friendslist - View all friends with numbers</color>");
			}
			ChatUI instance5 = ChatUI.Instance;
			if (instance5 != null)
			{
				instance5.AddMessage("<color=white>/removefriend <number> - Remove a friend</color>");
			}
			ChatUI instance6 = ChatUI.Instance;
			if (instance6 != null)
			{
				instance6.AddMessage("<color=white>/friends - Check which friends are online</color>");
			}
			ChatUI instance7 = ChatUI.Instance;
			if (instance7 != null)
			{
				instance7.AddMessage("<color=white>/crews - View all crews in your current stage</color>");
			}
			ChatUI instance8 = ChatUI.Instance;
			if (instance8 != null)
			{
				instance8.AddMessage("<color=white>/mycrew - View your crew members in your stage</color>");
			}
			ChatUI instance9 = ChatUI.Instance;
			if (instance9 != null)
			{
				instance9.AddMessage("<color=white>/listplayers - List all online players</color>");
			}
			ChatUI instance10 = ChatUI.Instance;
			if (instance10 != null)
			{
				instance10.AddMessage("<color=white>/block <number> - Block a player</color>");
			}
			ChatUI instance11 = ChatUI.Instance;
			if (instance11 != null)
			{
				instance11.AddMessage("<color=white>/unblock <number> - Unblock a player</color>");
			}
			ChatUI instance12 = ChatUI.Instance;
			if (instance12 != null)
			{
				instance12.AddMessage("<color=white>/blocklist - View all blocked players</color>");
			}
			ChatUI instance13 = ChatUI.Instance;
			if (instance13 != null)
			{
				instance13.AddMessage("<color=white>/friendguide - Show how to add friends</color>");
			}
			ChatUI instance14 = ChatUI.Instance;
			if (instance14 != null)
			{
				instance14.AddMessage("<color=white>/playershelp - Show this help message</color>");
			}
		}

		private static void HandleACNPlusHelpCommand()
		{
			ChatUI instance = ChatUI.Instance;
			if (instance != null)
			{
				instance.AddMessage("<color=green>=== ACNPlus Help ===</color>");
			}
			ChatUI instance2 = ChatUI.Instance;
			if (instance2 != null)
			{
				instance2.AddMessage("<color=white>/playershelp - Show player system commands</color>");
			}
			ChatUI instance3 = ChatUI.Instance;
			if (instance3 != null)
			{
				instance3.AddMessage("<color=white>/acnplushelp - Show this help message</color>");
			}
		}

		private static void HandleFriendGuideCommand()
		{
			ChatUI instance = ChatUI.Instance;
			if (instance != null)
			{
				instance.AddMessage("<color=green>To add a friend, have them tell you their id, which they get from the \"/AddMe\" command.</color>");
			}
			ChatUI instance2 = ChatUI.Instance;
			if (instance2 != null)
			{
				instance2.AddMessage("<color=green>Then you take that ID and use it in \"/AddFriend\". Example: \"/AddFriend 99\".</color>");
			}
		}

		private static void HandleCrewsCommand()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected I4, but got Unknown
			ClientController instance = ClientController.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				ChatUI instance2 = ChatUI.Instance;
				if (instance2 != null)
				{
					instance2.AddMessage("<color=red>Not connected to server!</color>");
				}
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			int num = (int)Utility.SceneNameToStage(((Scene)(ref activeScene)).name);
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
			foreach (MPPlayer value in instance.Players.Values)
			{
				if (value.ClientState == null || value.ClientState.Stage != num)
				{
					continue;
				}
				bool flag = false;
				if (value.ClientState.User != null && value.ClientState.User.Badges != null)
				{
					if (value.ClientState.User.Badges.Contains(63))
					{
						string key = "GCN";
						if (dictionary2.ContainsKey(key))
						{
							dictionary2[key]++;
						}
						else
						{
							dictionary2[key] = 1;
						}
						flag = true;
					}
					if (value.ClientState.User.Badges.Contains(40))
					{
						string key2 = "Goonforce";
						if (dictionary2.ContainsKey(key2))
						{
							dictionary2[key2]++;
						}
						else
						{
							dictionary2[key2] = 1;
						}
						flag = true;
					}
					if (value.ClientState.User.Badges.Contains(52))
					{
						string key3 = "rok";
						if (dictionary2.ContainsKey(key3))
						{
							dictionary2[key3]++;
						}
						else
						{
							dictionary2[key3] = 1;
						}
						flag = true;
					}
					if (value.ClientState.User.Badges.Contains(28))
					{
						string key4 = "dumfuks";
						if (dictionary2.ContainsKey(key4))
						{
							dictionary2[key4]++;
						}
						else
						{
							dictionary2[key4] = 1;
						}
						flag = true;
					}
				}
				if (!flag)
				{
					string key5 = (string.IsNullOrEmpty(value.ClientState.CrewName) ? "No Crew" : value.ClientState.CrewName);
					if (dictionary.ContainsKey(key5))
					{
						dictionary[key5]++;
					}
					else
					{
						dictionary[key5] = 1;
					}
				}
			}
			if (dictionary.Count == 0 && dictionary2.Count == 0)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage("<color=yellow>No players in your current stage!</color>");
				}
				return;
			}
			ChatUI instance4 = ChatUI.Instance;
			if (instance4 != null)
			{
				instance4.AddMessage($"<color=green>=== Crews in Stage {num} ===</color>");
			}
			if (dictionary2.Count > 0)
			{
				foreach (KeyValuePair<string, int> item in dictionary2.OrderByDescending((KeyValuePair<string, int> x) => x.Value))
				{
					string arg = ((item.Value == 1) ? "member" : "members");
					if (item.Key == "GCN")
					{
						ChatUI instance5 = ChatUI.Instance;
						if (instance5 != null)
						{
							instance5.AddMessage($"<sprite=63> <color=purple>GCN</color><color=white>: {item.Value} {arg}</color>");
						}
					}
					else if (item.Key == "Goonforce")
					{
						ChatUI instance6 = ChatUI.Instance;
						if (instance6 != null)
						{
							instance6.AddMessage($"<sprite=40> <color=blue>Goon</color><color=red>force</color><color=white>: {item.Value} {arg}</color>");
						}
					}
					else if (item.Key == "rok")
					{
						ChatUI instance7 = ChatUI.Instance;
						if (instance7 != null)
						{
							instance7.AddMessage($"<sprite=52> <color=#997777>rok</color><color=white>: {item.Value} {arg}</color>");
						}
					}
					else if (item.Key == "dumfuks")
					{
						ChatUI instance8 = ChatUI.Instance;
						if (instance8 != null)
						{
							instance8.AddMessage($"<sprite=28> <color=yellow>dumfuks</color><color=white>: {item.Value} {arg}</color>");
						}
					}
				}
				if (dictionary.Count > 0)
				{
					ChatUI instance9 = ChatUI.Instance;
					if (instance9 != null)
					{
						instance9.AddMessage("<color=white>---</color>");
					}
				}
			}
			foreach (KeyValuePair<string, int> item2 in dictionary.OrderByDescending((KeyValuePair<string, int> x) => x.Value))
			{
				string arg2 = ((item2.Value == 1) ? "member" : "members");
				ChatUI instance10 = ChatUI.Instance;
				if (instance10 != null)
				{
					instance10.AddMessage($"<color=white>{item2.Key}: {item2.Value} {arg2}</color>");
				}
			}
			int num2 = dictionary.Values.Sum() + dictionary2.Values.Sum();
			ChatUI instance11 = ChatUI.Instance;
			if (instance11 != null)
			{
				instance11.AddMessage($"<color=green>Total: {num2} players</color>");
			}
		}

		private static void HandleMyCrewCommand()
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected I4, but got Unknown
			ClientController instance = ClientController.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				ChatUI instance2 = ChatUI.Instance;
				if (instance2 != null)
				{
					instance2.AddMessage("<color=red>Not connected to server!</color>");
				}
				return;
			}
			MPPlayer val = ((IEnumerable<MPPlayer>)instance.Players.Values).FirstOrDefault((Func<MPPlayer, bool>)((MPPlayer p) => p.Local));
			if (val == null || val.ClientState == null)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage("<color=red>Could not find local player!</color>");
				}
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			int num = (int)Utility.SceneNameToStage(((Scene)(ref activeScene)).name);
			string crewName = val.ClientState.CrewName;
			bool flag = false;
			string text = "";
			int num2 = 0;
			if (val.ClientState.User != null && val.ClientState.User.Badges != null)
			{
				if (val.ClientState.User.Badges.Contains(63))
				{
					flag = true;
					text = "GCN";
					num2 = 63;
				}
				else if (val.ClientState.User.Badges.Contains(40))
				{
					flag = true;
					text = "Goonforce";
					num2 = 40;
				}
				else if (val.ClientState.User.Badges.Contains(52))
				{
					flag = true;
					text = "rok";
					num2 = 52;
				}
				else if (val.ClientState.User.Badges.Contains(28))
				{
					flag = true;
					text = "dumfuks";
					num2 = 28;
				}
			}
			if (!flag)
			{
				string playerDisplayName = MPUtility.GetPlayerDisplayName(val.ClientState);
				if (playerDisplayName.Contains("<sprite=63>"))
				{
					flag = true;
					text = "GCN";
					num2 = 63;
				}
				else if (playerDisplayName.Contains("<sprite=40>"))
				{
					flag = true;
					text = "Goonforce";
					num2 = 40;
				}
				else if (playerDisplayName.Contains("<sprite=52>"))
				{
					flag = true;
					text = "rok";
					num2 = 52;
				}
				else if (playerDisplayName.Contains("<sprite=28>"))
				{
					flag = true;
					text = "dumfuks";
					num2 = 28;
				}
			}
			if (!flag && string.IsNullOrEmpty(crewName))
			{
				ChatUI instance4 = ChatUI.Instance;
				if (instance4 != null)
				{
					instance4.AddMessage("<color=yellow>You are not in a crew!</color>");
				}
				return;
			}
			List<string> list = new List<string>();
			foreach (MPPlayer value in instance.Players.Values)
			{
				if (value.ClientState == null || value.ClientId == instance.LocalID || value.ClientState.Stage != num)
				{
					continue;
				}
				if (flag)
				{
					bool flag2 = false;
					if (value.ClientState.User != null && value.ClientState.User.Badges != null && value.ClientState.User.Badges.Contains(num2))
					{
						flag2 = true;
					}
					if (!flag2 && MPUtility.GetPlayerDisplayName(value.ClientState).Contains($"<sprite={num2}>"))
					{
						flag2 = true;
					}
					if (flag2)
					{
						list.Add(value.ClientState.Name);
					}
				}
				else if (value.ClientState.CrewName == crewName)
				{
					list.Add(value.ClientState.Name);
				}
			}
			if (list.Count == 0)
			{
				if (flag)
				{
					switch (text)
					{
					case "GCN":
					{
						ChatUI instance8 = ChatUI.Instance;
						if (instance8 != null)
						{
							instance8.AddMessage("<color=yellow>No other <sprite=63> <color=purple>GCN</color> crew members in your stage!</color>");
						}
						break;
					}
					case "Goonforce":
					{
						ChatUI instance6 = ChatUI.Instance;
						if (instance6 != null)
						{
							instance6.AddMessage("<color=yellow>No other <sprite=40> <color=blue>Goon</color><color=red>force</color> crew members in your stage!</color>");
						}
						break;
					}
					case "rok":
					{
						ChatUI instance7 = ChatUI.Instance;
						if (instance7 != null)
						{
							instance7.AddMessage("<color=yellow>No other <sprite=52> <color=#997777>rok</color> crew members in your stage!</color>");
						}
						break;
					}
					case "dumfuks":
					{
						ChatUI instance5 = ChatUI.Instance;
						if (instance5 != null)
						{
							instance5.AddMessage("<color=yellow>No other <sprite=28> <color=yellow>dumfuks</color> crew members in your stage!</color>");
						}
						break;
					}
					}
				}
				else
				{
					ChatUI instance9 = ChatUI.Instance;
					if (instance9 != null)
					{
						instance9.AddMessage("<color=yellow>No other " + crewName + " crew members in your stage!</color>");
					}
				}
				return;
			}
			if (flag)
			{
				switch (text)
				{
				case "GCN":
				{
					ChatUI instance13 = ChatUI.Instance;
					if (instance13 != null)
					{
						instance13.AddMessage($"<sprite=63> <color=purple>GCN</color><color=green> Members in Stage {num} ===</color>");
					}
					break;
				}
				case "Goonforce":
				{
					ChatUI instance11 = ChatUI.Instance;
					if (instance11 != null)
					{
						instance11.AddMessage($"<sprite=40> <color=blue>Goon</color><color=red>force</color><color=green> Members in Stage {num} ===</color>");
					}
					break;
				}
				case "rok":
				{
					ChatUI instance12 = ChatUI.Instance;
					if (instance12 != null)
					{
						instance12.AddMessage($"<sprite=52> <color=#997777>rok</color><color=green> Members in Stage {num} ===</color>");
					}
					break;
				}
				case "dumfuks":
				{
					ChatUI instance10 = ChatUI.Instance;
					if (instance10 != null)
					{
						instance10.AddMessage($"<sprite=28> <color=yellow>dumfuks</color><color=green> Members in Stage {num} ===</color>");
					}
					break;
				}
				}
			}
			else
			{
				ChatUI instance14 = ChatUI.Instance;
				if (instance14 != null)
				{
					instance14.AddMessage($"<color=green>=== {crewName} Members in Stage {num} ===</color>");
				}
			}
			foreach (string item in list.OrderBy((string x) => x))
			{
				ChatUI instance15 = ChatUI.Instance;
				if (instance15 != null)
				{
					instance15.AddMessage("<color=white>• " + item + "</color>");
				}
			}
			string arg = ((list.Count == 1) ? "member" : "members");
			ChatUI instance16 = ChatUI.Instance;
			if (instance16 != null)
			{
				instance16.AddMessage($"<color=green>Total: {list.Count} {arg}</color>");
			}
		}

		private static void HandleListPlayersCommand()
		{
			ClientController instance = ClientController.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				ChatUI instance2 = ChatUI.Instance;
				if (instance2 != null)
				{
					instance2.AddMessage("<color=red>Not connected to server!</color>");
				}
				return;
			}
			List<MPPlayer> list = (from p in instance.Players.Values
				where p.ClientState != null
				orderby p.ClientState.Name
				select p).ToList();
			if (list.Count == 0)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage("<color=yellow>No players online!</color>");
				}
				return;
			}
			ChatUI instance4 = ChatUI.Instance;
			if (instance4 != null)
			{
				instance4.AddMessage("<color=green>=== All Players ===</color>");
			}
			for (int i = 0; i < list.Count; i++)
			{
				MPPlayer val = list[i];
				string arg = (ACNPlusPlugin.GetBlocklist().Contains(val.ClientState.Name) ? " <color=red>[BLOCKED]</color>" : "");
				ChatUI instance5 = ChatUI.Instance;
				if (instance5 != null)
				{
					instance5.AddMessage($"<color=white>{i + 1}. {val.ClientState.Name}{arg}</color>");
				}
			}
			ChatUI instance6 = ChatUI.Instance;
			if (instance6 != null)
			{
				instance6.AddMessage($"<color=green>Total: {list.Count} players</color>");
			}
		}

		private static void HandleBlockCommand(string numberStr)
		{
			if (!int.TryParse(numberStr, out var result) || result < 1)
			{
				ChatUI instance = ChatUI.Instance;
				if (instance != null)
				{
					instance.AddMessage("<color=red>Invalid number! Must be a positive number.</color>");
				}
				return;
			}
			ClientController instance2 = ClientController.Instance;
			if ((Object)(object)instance2 == (Object)null)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage("<color=red>Not connected to server!</color>");
				}
				return;
			}
			List<MPPlayer> list = (from p in instance2.Players.Values
				where p.ClientState != null
				orderby p.ClientState.Name
				select p).ToList();
			if (result > list.Count)
			{
				ChatUI instance4 = ChatUI.Instance;
				if (instance4 != null)
				{
					instance4.AddMessage($"<color=red>Invalid number! Only {list.Count} players online.</color>");
				}
				return;
			}
			MPPlayer obj = list[result - 1];
			string name = obj.ClientState.Name;
			if (obj.ClientId == instance2.LocalID)
			{
				ChatUI instance5 = ChatUI.Instance;
				if (instance5 != null)
				{
					instance5.AddMessage("<color=red>You cannot block yourself!</color>");
				}
				return;
			}
			if (ACNPlusPlugin.GetBlocklist().Contains(name))
			{
				ChatUI instance6 = ChatUI.Instance;
				if (instance6 != null)
				{
					instance6.AddMessage("<color=yellow>" + name + " is already blocked!</color>");
				}
				return;
			}
			try
			{
				File.AppendAllText(ACNPlusPlugin.GetBlocklistPath(), name + Environment.NewLine);
				ACNPlusPlugin.ReloadBlocklist();
				ChatUI instance7 = ChatUI.Instance;
				if (instance7 != null)
				{
					instance7.AddMessage("<color=green>Blocked " + name + "!</color>");
				}
			}
			catch (Exception)
			{
				ChatUI instance8 = ChatUI.Instance;
				if (instance8 != null)
				{
					instance8.AddMessage("<color=red>Failed to save to blocklist!</color>");
				}
			}
		}

		private static void HandleUnblockCommand(string numberStr)
		{
			if (!int.TryParse(numberStr, out var result) || result < 1)
			{
				ChatUI instance = ChatUI.Instance;
				if (instance != null)
				{
					instance.AddMessage("<color=red>Invalid number! Must be a positive number.</color>");
				}
				return;
			}
			HashSet<string> blocklist = ACNPlusPlugin.GetBlocklist();
			if (blocklist.Count == 0)
			{
				ChatUI instance2 = ChatUI.Instance;
				if (instance2 != null)
				{
					instance2.AddMessage("<color=yellow>Your blocklist is empty!</color>");
				}
				return;
			}
			if (result > blocklist.Count)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage($"<color=red>Invalid number! You only have {blocklist.Count} blocked users.</color>");
				}
				return;
			}
			string text = blocklist.ToArray()[result - 1];
			try
			{
				blocklist.Remove(text);
				File.WriteAllLines(ACNPlusPlugin.GetBlocklistPath(), blocklist);
				ACNPlusPlugin.ReloadBlocklist();
				ChatUI instance4 = ChatUI.Instance;
				if (instance4 != null)
				{
					instance4.AddMessage("<color=green>Unblocked " + text + "!</color>");
				}
			}
			catch (Exception)
			{
				ChatUI instance5 = ChatUI.Instance;
				if (instance5 != null)
				{
					instance5.AddMessage("<color=red>Failed to update blocklist!</color>");
				}
			}
		}

		private static void HandleBlocklistCommand()
		{
			HashSet<string> blocklist = ACNPlusPlugin.GetBlocklist();
			if (blocklist.Count == 0)
			{
				ChatUI instance = ChatUI.Instance;
				if (instance != null)
				{
					instance.AddMessage("<color=yellow>Your blocklist is empty!</color>");
				}
				return;
			}
			ChatUI instance2 = ChatUI.Instance;
			if (instance2 != null)
			{
				instance2.AddMessage("<color=green>=== Blocked Players ===</color>");
			}
			string[] array = blocklist.ToArray();
			for (int i = 0; i < array.Length; i++)
			{
				ChatUI instance3 = ChatUI.Instance;
				if (instance3 != null)
				{
					instance3.AddMessage($"<color=white>{i + 1}. {array[i]}</color>");
				}
			}
			ChatUI instance4 = ChatUI.Instance;
			if (instance4 != null)
			{
				instance4.AddMessage($"<color=green>Total: {blocklist.Count} blocked</color>");
			}
		}
	}
	public class FriendsListPatches
	{
	}
	public static class LobbyBannerPatches
	{
		[HarmonyPatch(typeof(LobbyUI), "UpdateUI")]
		private class LobbyUIUpdateUIPatch
		{
			private static void Postfix(LobbyUI __instance)
			{
				FieldInfo field = typeof(LobbyUI).GetField("_lobbySettings", BindingFlags.Instance | BindingFlags.NonPublic);
				if (!(field == null))
				{
					object? value = field.GetValue(__instance);
					Component val = (Component)((value is Component) ? value : null);
					if ((Object)(object)val != (Object)null)
					{
						val.gameObject.SetActive(!ACNPlusPlugin.HideLobbySettings.Value);
					}
				}
			}
		}

		[HarmonyPatch(typeof(LobbyUI), "Awake")]
		private class LobbyUIAwakePatch
		{
			private static void Postfix(LobbyUI __instance)
			{
				//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
				FieldInfo field = typeof(LobbyUI).GetField("_lobbySettings", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field != null)
				{
					object? value = field.GetValue(__instance);
					Component val = (Component)((value is Component) ? value : null);
					if (val != null)
					{
						val.gameObject.SetActive(!ACNPlusPlugin.HideLobbySettings.Value);
					}
				}
				if (!ACNPlusPlugin.TransparentLobbyBanner.Value)
				{
					return;
				}
				Sprite val2 = LoadTransparentSprite();
				if ((Object)(object)val2 == (Object)null)
				{
					return;
				}
				FieldInfo field2 = typeof(LobbyUI).GetField("_canvas", BindingFlags.Instance | BindingFlags.NonPublic);
				if (field2 == null)
				{
					return;
				}
				object? value2 = field2.GetValue(__instance);
				GameObject val3 = (GameObject)((value2 is GameObject) ? value2 : null);
				if ((Object)(object)val3 == (Object)null)
				{
					return;
				}
				Transform val4 = val3.transform.Find("Lobby Name BG");
				if ((Object)(object)val4 == (Object)null)
				{
					return;
				}
				Type type = Type.GetType("UnityEngine.UI.Image, UnityEngine.UI");
				if (!(type == null))
				{
					Component component = ((Component)val4).GetComponent(type);
					if ((Object)(object)component != (Object)null)
					{
						SetImageSprite(component, val2);
						SetImageColor(component, Color.white);
					}
				}
			}
		}

		[HarmonyPatch(typeof(LobbyPlayerUI), "Awake")]
		private class LobbyPlayerUIAwakePatch
		{
			private static void Postfix(LobbyPlayerUI __instance)
			{
				if (!ACNPlusPlugin.TransparentLobbyNameBG.Value)
				{
					return;
				}
				Sprite val = LoadTransparentSprite();
				if (!((Object)(object)val == (Object)null))
				{
					FieldInfo? field = typeof(LobbyPlayerUI).GetField("_bg", BindingFlags.Instance | BindingFlags.NonPublic);
					FieldInfo field2 = typeof(LobbyPlayerUI).GetField("_teamBg", BindingFlags.Instance | BindingFlags.NonPublic);
					object obj = field?.GetValue(__instance);
					object obj2 = field2?.GetValue(__instance);
					if (obj != null)
					{
						SetImageSprite(obj, val);
					}
					if (obj2 != null)
					{
						SetImageSprite(obj2, val);
					}
				}
			}
		}

		[HarmonyPatch(typeof(LobbyPlayerUI), "SetTeam")]
		private class LobbyPlayerUISetTeamPatch
		{
			private static void Postfix(LobbyPlayerUI __instance)
			{
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				if (ACNPlusPlugin.TransparentLobbyNameBG.Value)
				{
					object obj = typeof(LobbyPlayerUI).GetField("_teamBg", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
					if (obj != null)
					{
						float imageColorA = GetImageColorA(obj);
						SetImageColor(obj, new Color(1f, 1f, 1f, imageColorA));
					}
				}
			}
		}

		[HarmonyPatch(typeof(LobbyPlayerUI), "SetPlayer")]
		private class LobbyPlayerUISetPlayerPatch
		{
			private static void Postfix(LobbyPlayerUI __instance)
			{
				//IL_004c: Unknown result type (might be due to invalid IL or missing references)
				if (ACNPlusPlugin.TransparentLobbyNameBG.Value)
				{
					object obj = typeof(LobbyPlayerUI).GetField("_teamBg", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance);
					if (obj != null)
					{
						float imageColorA = GetImageColorA(obj);
						SetImageColor(obj, new Color(1f, 1f, 1f, imageColorA));
					}
				}
			}
		}

		private static Sprite _cachedTransparent;

		private static Sprite LoadTransparentSprite()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_cachedTransparent != (Object)null)
			{
				return _cachedTransparent;
			}
			string backendTexturesPath = ACNPlusPlugin.GetBackendTexturesPath("transparent.png");
			if (!File.Exists(backendTexturesPath))
			{
				return null;
			}
			byte[] array = File.ReadAllBytes(backendTexturesPath);
			Texture2D val = new Texture2D(2, 2);
			if (!ImageConversion.LoadImage(val, array))
			{
				return null;
			}
			val.Apply();
			_cachedTransparent = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			return _cachedTransparent;
		}

		private static void SetImageSprite(object image, Sprite sprite)
		{
			if (image != null && !((Object)(object)sprite == (Object)null))
			{
				image.GetType().GetProperty("sprite", BindingFlags.Instance | BindingFlags.Public)?.SetValue(image, sprite);
			}
		}

		private static void SetImageColor(object image, Color color)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			image?.GetType().GetProperty("color", BindingFlags.Instance | BindingFlags.Public)?.SetValue(image, color);
		}

		private static float GetImageColorA(object image)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (image == null)
			{
				return 1f;
			}
			if (image.GetType().GetProperty("color", BindingFlags.Instance | BindingFlags.Public)?.GetValue(image) is Color val)
			{
				return val.a;
			}
			return 1f;
		}
	}
	[HarmonyPatch(typeof(ClientController), "OnMessageReceived")]
	public class LobbyInvitePatches
	{
		[HarmonyPrefix]
		public static bool OnMessageReceived_Prefix(object sender, MessageReceivedEventArgs e)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Invalid comparison between Unknown and I4
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Packets val = (Packets)e.MessageId;
			if ((int)val == 27)
			{
				Packet obj = PacketFactory.PacketFromMessage(val, e.Message);
				ServerLobbyInvite val2 = (ServerLobbyInvite)(object)((obj is ServerLobbyInvite) ? obj : null);
				if (val2 != null)
				{
					ClientController instance = ClientController.Instance;
					if ((Object)(object)instance != (Object)null)
					{
						string text = "Unknown";
						if (instance.Players.TryGetValue(val2.InviterId, out var value) && value.ClientState != null)
						{
							text = value.ClientState.Name;
						}
						if (ACNPlusPlugin.GetBlocklist().Contains(text))
						{
							instance.ClientLobbyManager.DeclineInvite(val2.LobbyId);
							if (ACNPlusPlugin.SeeWhenSomethingIsBlocked.Value)
							{
								ChatUI instance2 = ChatUI.Instance;
								if (instance2 != null)
								{
									instance2.AddMessage("<color=red>Blocked invite from " + text + "</color>");
								}
							}
							return false;
						}
						if (ACNPlusPlugin.BlockInvites.Value)
						{
							instance.ClientLobbyManager.DeclineInvite(val2.LobbyId);
							if (ACNPlusPlugin.BlockInvitesChatMessage.Value)
							{
								string text2 = "Unknown";
								if (instance.ClientLobbyManager.Lobbies.TryGetValue(val2.LobbyId, out var _))
								{
									text2 = instance.ClientLobbyManager.GetLobbyName(val2.LobbyId);
								}
								ChatUI instance3 = ChatUI.Instance;
								if (instance3 != null)
								{
									instance3.AddMessage("<color=yellow>Blocked invite from " + text + " to " + text2 + " lobby</color>");
								}
							}
							return false;
						}
					}
				}
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MPMapUI), "Awake")]
	public static class MinimapReplacementPatch
	{
		private const string RawImageTypeName = "UnityEngine.UI.RawImage";

		[HarmonyPostfix]
		public static void Awake_Postfix(MPMapUI __instance)
		{
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			string text = null;
			ConfigEntry<bool> catWizardMiniMap = ACNPlusPlugin.CatWizardMiniMap;
			if (catWizardMiniMap != null && catWizardMiniMap.Value)
			{
				text = ACNPlusPlugin.GetBackendTexturesPath("CatMiniMap.png");
			}
			else
			{
				ConfigEntry<bool> changeMiniMapToPNG = ACNPlusPlugin.ChangeMiniMapToPNG;
				if (changeMiniMapToPNG != null && changeMiniMapToPNG.Value)
				{
					string texturesFolder = ACNPlusPlugin.GetTexturesFolder();
					if (!string.IsNullOrEmpty(texturesFolder) && Directory.Exists(texturesFolder))
					{
						text = Path.Combine(texturesFolder, "MiniMapPNG.png");
					}
				}
			}
			if (text == null || !File.Exists(text))
			{
				return;
			}
			Transform val = ((Component)__instance).transform.Find("Map Texture");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Component val2 = null;
			Component[] components = ((Component)val).GetComponents<Component>();
			foreach (Component val3 in components)
			{
				if ((Object)(object)val3 != (Object)null && ((object)val3).GetType().FullName == "UnityEngine.UI.RawImage")
				{
					val2 = val3;
					break;
				}
			}
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			try
			{
				byte[] array = File.ReadAllBytes(text);
				Texture2D val4 = new Texture2D(2, 2);
				if (ImageConversion.LoadImage(val4, array))
				{
					((object)val2).GetType().GetProperty("texture", BindingFlags.Instance | BindingFlags.Public)?.SetValue(val2, val4);
					((Component)__instance).gameObject.AddComponent<MinimapTextureHolder>().SetTexture((Texture)(object)val4);
				}
				else
				{
					Object.Destroy((Object)(object)val4);
				}
			}
			catch (Exception)
			{
			}
		}
	}
	[HarmonyPatch(typeof(ClientLobbyManager), "OnPacketReceived")]
	public class PrivateLobbyPatches
	{
		private static HashSet<ushort> _allowedPlayers = new HashSet<ushort>();

		private static bool _wasHost = false;

		[HarmonyPostfix]
		public static void OnPacketReceived_Postfix(Packets packetId, Packet packet)
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Invalid comparison between Unknown and I4
			ClientController instance = ClientController.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			ClientLobbyManager clientLobbyManager = instance.ClientLobbyManager;
			Lobby currentLobby = clientLobbyManager.CurrentLobby;
			if (currentLobby == null)
			{
				_allowedPlayers.Clear();
				_wasHost = false;
				return;
			}
			bool flag = currentLobby.LobbyState.HostId == instance.LocalID;
			if (flag && !_wasHost)
			{
				_allowedPlayers.Clear();
				foreach (ushort key in currentLobby.LobbyState.Players.Keys)
				{
					_allowedPlayers.Add(key);
				}
				_wasHost = true;
			}
			else if (!flag)
			{
				_wasHost = false;
				_allowedPlayers.Clear();
				return;
			}
			if (((int)packetId != 47 && (int)packetId != 13) || !flag)
			{
				return;
			}
			HashSet<string> blocklist = ACNPlusPlugin.GetBlocklist();
			HashSet<string> friendsList = ACNPlusPlugin.GetFriendsList();
			MPPlayer val = ((IEnumerable<MPPlayer>)instance.Players.Values).FirstOrDefault((Func<MPPlayer, bool>)((MPPlayer p) => p.Local));
			string text = "";
			int num = -1;
			if (val != null && val.ClientState != null)
			{
				text = val.ClientState.CrewName;
				if (val.ClientState.User != null && val.ClientState.User.Badges != null)
				{
					if (val.ClientState.User.Badges.Contains(63))
					{
						num = 63;
					}
					else if (val.ClientState.User.Badges.Contains(40))
					{
						num = 40;
					}
					else if (val.ClientState.User.Badges.Contains(52))
					{
						num = 52;
					}
					else if (val.ClientState.User.Badges.Contains(28))
					{
						num = 28;
					}
				}
				if (num == -1)
				{
					string playerDisplayName = MPUtility.GetPlayerDisplayName(val.ClientState);
					if (playerDisplayName.Contains("<sprite=63>"))
					{
						num = 63;
					}
					else if (playerDisplayName.Contains("<sprite=40>"))
					{
						num = 40;
					}
					else if (playerDisplayName.Contains("<sprite=52>"))
					{
						num = 52;
					}
					else if (playerDisplayName.Contains("<sprite=28>"))
					{
						num = 28;
					}
				}
			}
			foreach (ushort key2 in currentLobby.LobbyState.Players.Keys)
			{
				if (key2 == instance.LocalID)
				{
					continue;
				}
				if (instance.Players.TryGetValue(key2, out var value) && value.ClientState != null)
				{
					string name = value.ClientState.Name;
					if (blocklist.Contains(name))
					{
						clientLobbyManager.KickPlayer(key2);
						if (ACNPlusPlugin.SeeWhenSomethingIsBlocked.Value)
						{
							ChatUI instance2 = ChatUI.Instance;
							if (instance2 != null)
							{
								instance2.AddMessage("<color=red>Auto-kicked blocked user " + name + " from your lobby</color>");
							}
						}
						continue;
					}
					if (ACNPlusPlugin.CrewOnlyLobby.Value)
					{
						bool flag2 = false;
						if (num != -1)
						{
							if (value.ClientState.User != null && value.ClientState.User.Badges != null && value.ClientState.User.Badges.Contains(num))
							{
								flag2 = true;
							}
							if (!flag2 && MPUtility.GetPlayerDisplayName(value.ClientState).Contains($"<sprite={num}>"))
							{
								flag2 = true;
							}
						}
						else if (!string.IsNullOrEmpty(text) && value.ClientState.CrewName == text)
						{
							flag2 = true;
						}
						if (!flag2)
						{
							clientLobbyManager.KickPlayer(key2);
							ChatUI instance3 = ChatUI.Instance;
							if (instance3 != null)
							{
								instance3.AddMessage("<color=yellow>Auto-kicked " + name + " (not in your crew)</color>");
							}
							continue;
						}
					}
					if (ACNPlusPlugin.FriendsOnlyLobby.Value && !friendsList.Contains(name))
					{
						clientLobbyManager.KickPlayer(key2);
						ChatUI instance4 = ChatUI.Instance;
						if (instance4 != null)
						{
							instance4.AddMessage("<color=yellow>Auto-kicked " + name + " (not on friends list)</color>");
						}
						continue;
					}
				}
				if (ACNPlusPlugin.BlockPlayersFromJoiningLobby.Value && !_allowedPlayers.Contains(key2))
				{
					clientLobbyManager.KickPlayer(key2);
					string text2 = "Unknown";
					if (instance.Players.TryGetValue(key2, out var value2) && value2.ClientState != null)
					{
						text2 = value2.ClientState.Name;
					}
					ChatUI instance5 = ChatUI.Instance;
					if (instance5 != null)
					{
						instance5.AddMessage("<color=yellow>Auto-kicked " + text2 + " from your lobby</color>");
					}
				}
			}
		}
	}
}
namespace ACNPlus.MinimapReplacement
{
	public class MinimapTextureHolder : MonoBehaviour
	{
		private Texture _texture;

		public void SetTexture(Texture texture)
		{
			_texture = texture;
		}

		private void OnDestroy()
		{
			if ((Object)(object)_texture != (Object)null)
			{
				Object.Destroy((Object)(object)_texture);
				_texture = null;
			}
		}
	}
}