Decompiled source of SteamBanning v1.0.0

SteamBanning.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using UnityEngine;
using VoidManager;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("SteamBanning")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SteamBanning")]
[assembly: AssemblyTitle("SteamBanning")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SteamBanning
{
	internal class BanListManager
	{
		internal Dictionary<CSteamID, string> BannedUsers;

		public static BanListManager Instance { get; internal set; }

		public BanListManager()
		{
			LoadBannedSteamIDs();
		}

		internal void OnPlayerJoin(object source, PlayerEventArgs PlayerEventArg)
		{
			//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)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			Player player = PlayerEventArg.player;
			CSteamID steamID = (CSteamID)ulong.Parse(player.UserId);
			if (BanListContainsSteamID(steamID))
			{
				if (PhotonNetwork.IsMasterClient)
				{
					BepinPlugin.Log.LogInfo((object)("Closing connection from banned user " + player.NickName + " Steam ID: " + player.UserId));
					PhotonNetwork.CloseConnection(player);
				}
				else
				{
					string text = "Banned user " + player.NickName + " has joined the session. SteamID: " + player.UserId;
					BepinPlugin.Log.LogInfo((object)text);
					Messaging.Echo(text, true);
				}
			}
		}

		public bool BanListContainsSteamID(CSteamID steamID)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (BannedUsers.ContainsKey(steamID))
			{
				return true;
			}
			return false;
		}

		public void RemoveFromBanlist(CSteamID steamID)
		{
			//IL_0002: 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)
			if (BanListContainsSteamID(steamID))
			{
				BannedUsers.Remove(steamID);
				UpdateConfigFile();
			}
		}

		public void AddToBanlist(CSteamID steamID, string UserName)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!BanListContainsSteamID(steamID))
			{
				BannedUsers.Add(steamID, UserName);
				UpdateConfigFile();
			}
		}

		private void LoadBannedSteamIDs()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			BannedUsers = new Dictionary<CSteamID, string>();
			string[] array = BepinPlugin.Bindings.BanList.Value.Split(new char[1] { ',' });
			if (array.Length <= 1 && Utility.IsNullOrWhiteSpace(array[0]))
			{
				return;
			}
			string[] array2 = array;
			foreach (string text in array2)
			{
				string[] array3 = text.Split(new char[1] { ':' }, 2);
				ulong result;
				if (array3.Length != 2)
				{
					BepinPlugin.Log.LogError((object)(array3.Length + " Bad user data: " + text));
				}
				else if (ulong.TryParse(array3[0], out result))
				{
					CSteamID val = (CSteamID)result;
					if (((CSteamID)(ref val)).IsValid())
					{
						if (!BanListContainsSteamID(val))
						{
							BannedUsers.Add(val, array3[1]);
						}
						else
						{
							BepinPlugin.Log.LogError((object)("Duplicate SteamID: " + text));
						}
					}
					else
					{
						BepinPlugin.Log.LogError((object)("Bad SteamID: " + text));
					}
				}
				else
				{
					BepinPlugin.Log.LogError((object)("Bad SteamID Parse: " + text));
				}
			}
		}

		private void UpdateConfigFile()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			bool flag = true;
			string text = string.Empty;
			foreach (KeyValuePair<CSteamID, string> bannedUser in BannedUsers)
			{
				if (flag)
				{
					flag = false;
				}
				else
				{
					text += ",";
				}
				text += $"{bannedUser.Key}:{bannedUser.Value}";
			}
			BepinPlugin.Bindings.BanList.Value = text;
		}
	}
	internal class BanningGUI : ModSettingsMenu
	{
		private class UserDisplayObject
		{
			public string PlayerName;

			public CSteamID SteamID;

			public Player PhotonPlayer;

			public UserDisplayObject(CSteamID steamID, Player photonPlayer)
			{
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				PlayerName = photonPlayer.NickName;
				SteamID = steamID;
				PhotonPlayer = photonPlayer;
			}

			public UserDisplayObject(CSteamID steamID, string playerName)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				PlayerName = playerName;
				SteamID = steamID;
			}
		}

		private UserDisplayObject SelectedUser;

		private UserDisplayObject[] UserDisplayObjects = null;

		private Vector2 ScrollPosition = Vector2.zero;

		private float LastUpdateTime = 0f;

		private bool BanUIOpen = true;

		public override string Name()
		{
			return "Steam Banning";
		}

		private void UpdateUserDisplayObjectsForBanning()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			Player[] playerListOthers = PhotonNetwork.PlayerListOthers;
			List<UserDisplayObject> list;
			if (UserDisplayObjects == null)
			{
				list = new List<UserDisplayObject>();
				Player[] array = playerListOthers;
				foreach (Player val in array)
				{
					if (ulong.TryParse(val.UserId, out var result))
					{
						list.Add(new UserDisplayObject((CSteamID)result, val));
					}
					else
					{
						BepinPlugin.Log.LogWarning((object)("Could not parse steam ID for user: " + val.NickName));
					}
				}
				UserDisplayObjects = list.ToArray();
				return;
			}
			list = UserDisplayObjects.ToList();
			List<UserDisplayObject> list2 = new List<UserDisplayObject>();
			foreach (UserDisplayObject item in list)
			{
				bool flag = false;
				Player[] array2 = playerListOthers;
				foreach (Player val2 in array2)
				{
					if (val2 == item.PhotonPlayer)
					{
						flag = true;
					}
				}
				if (!flag)
				{
					list2.Add(item);
				}
			}
			foreach (UserDisplayObject item2 in list2)
			{
				if (SelectedUser == item2)
				{
					SelectedUser = null;
				}
				list.Remove(item2);
			}
			Player[] array3 = playerListOthers;
			foreach (Player val3 in array3)
			{
				bool flag2 = false;
				foreach (UserDisplayObject item3 in list)
				{
					if (val3 == item3.PhotonPlayer)
					{
						flag2 = true;
						break;
					}
				}
				if (!flag2)
				{
					if (ulong.TryParse(val3.UserId, out var result2))
					{
						list.Add(new UserDisplayObject((CSteamID)result2, val3));
					}
					else
					{
						BepinPlugin.Log.LogWarning((object)("Could not parse steam ID for user: " + val3.NickName));
					}
				}
			}
			UserDisplayObjects = list.ToArray();
		}

		private void UpdateUDOsForUnBanning()
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			List<UserDisplayObject> list;
			if (UserDisplayObjects == null)
			{
				list = new List<UserDisplayObject>();
				foreach (KeyValuePair<CSteamID, string> bannedUser in BanListManager.Instance.BannedUsers)
				{
					list.Add(new UserDisplayObject(bannedUser.Key, bannedUser.Value));
				}
				UserDisplayObjects = list.ToArray();
				return;
			}
			list = UserDisplayObjects.ToList();
			List<UserDisplayObject> list2 = new List<UserDisplayObject>();
			foreach (UserDisplayObject item in list)
			{
				if (!BanListManager.Instance.BanListContainsSteamID(item.SteamID))
				{
					list2.Add(item);
				}
			}
			foreach (UserDisplayObject item2 in list2)
			{
				if (SelectedUser == item2)
				{
					SelectedUser = null;
				}
				list.Remove(item2);
			}
			UserDisplayObjects = list.ToArray();
		}

		private void BanningUI()
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: 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)
			if (!PhotonNetwork.InRoom)
			{
				if (UserDisplayObjects != null)
				{
					UserDisplayObjects = null;
				}
				GUILayout.Label("Not in a room", Array.Empty<GUILayoutOption>());
				return;
			}
			if (Time.time > LastUpdateTime + 5f)
			{
				LastUpdateTime = Time.time;
				UpdateUserDisplayObjectsForBanning();
			}
			if (UserDisplayObjects == null)
			{
				GUILayout.Label("No Data", Array.Empty<GUILayoutOption>());
				return;
			}
			GUILayout.Label("Player List", Array.Empty<GUILayoutOption>());
			ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, Array.Empty<GUILayoutOption>());
			UserDisplayObject[] userDisplayObjects = UserDisplayObjects;
			foreach (UserDisplayObject userDisplayObject in userDisplayObjects)
			{
				bool flag = BanListManager.Instance.BanListContainsSteamID(userDisplayObject.SteamID);
				if (flag)
				{
					GUI.color = Color.red;
				}
				else
				{
					GUI.color = Color.white;
				}
				if (GUILayout.Button(string.Format("{0} - {1}{2}", userDisplayObject.SteamID, userDisplayObject.PlayerName, flag ? " [BANNED]" : string.Empty), Array.Empty<GUILayoutOption>()))
				{
					SelectedUser = userDisplayObject;
				}
			}
			GUILayout.EndScrollView();
			GUILayout.Label("Selected user: " + ((SelectedUser != null) ? SelectedUser.PlayerName : "No User Selected"), Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUI.color = Color.red;
			if (GUILayout.Button("Ban", Array.Empty<GUILayoutOption>()) && SelectedUser != null)
			{
				MenuScreenController.Instance.ShowConfirmationPopup("Ban User: " + SelectedUser.PlayerName, "Are you sure?", (Action)BanDelegate, (Action)null);
			}
			GUI.color = Color.white;
			if (GUILayout.Button("Unban", Array.Empty<GUILayoutOption>()) && SelectedUser != null)
			{
				BanListManager.Instance.RemoveFromBanlist(SelectedUser.SteamID);
				BepinPlugin.Log.LogInfo((object)("Unbanned user: " + SelectedUser.PlayerName));
				Messaging.Echo("Unbanned user: " + SelectedUser.PlayerName, false);
			}
			GUILayout.EndHorizontal();
		}

		private void UnBanningUI()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00b2: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time > LastUpdateTime + 5f)
			{
				LastUpdateTime = Time.time;
				UpdateUDOsForUnBanning();
			}
			if (UserDisplayObjects == null)
			{
				GUILayout.Label("No Data", Array.Empty<GUILayoutOption>());
				return;
			}
			GUILayout.Label("Player List", Array.Empty<GUILayoutOption>());
			ScrollPosition = GUILayout.BeginScrollView(ScrollPosition, Array.Empty<GUILayoutOption>());
			UserDisplayObject[] userDisplayObjects = UserDisplayObjects;
			foreach (UserDisplayObject userDisplayObject in userDisplayObjects)
			{
				bool flag = BanListManager.Instance.BanListContainsSteamID(userDisplayObject.SteamID);
				if (flag)
				{
					GUI.color = Color.red;
				}
				else
				{
					GUI.color = Color.white;
				}
				if (GUILayout.Button(string.Format("{0} - {1}{2}", userDisplayObject.SteamID, userDisplayObject.PlayerName, flag ? " [BANNED]" : " [UNBANNED]"), Array.Empty<GUILayoutOption>()))
				{
					SelectedUser = userDisplayObject;
				}
			}
			GUILayout.EndScrollView();
			GUI.color = Color.white;
			GUILayout.Label("Selected user: " + ((SelectedUser != null) ? SelectedUser.PlayerName : "No User Selected"), Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Unban", Array.Empty<GUILayoutOption>()) && SelectedUser != null)
			{
				BanListManager.Instance.RemoveFromBanlist(SelectedUser.SteamID);
				BepinPlugin.Log.LogInfo((object)("Unbanned user: " + SelectedUser.PlayerName));
				if (Game.InGame)
				{
					Messaging.Echo("Unbanned user: " + SelectedUser.PlayerName, false);
				}
			}
		}

		public override void Draw()
		{
			if (BanUIOpen)
			{
				BanningUI();
			}
			else
			{
				UnBanningUI();
			}
			if (GUILayout.Button(BanUIOpen ? "View Banlist" : "Open Banning Menu", Array.Empty<GUILayoutOption>()))
			{
				BanUIOpen = !BanUIOpen;
				SelectedUser = null;
				UserDisplayObjects = null;
			}
		}

		public override void OnOpen()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			ScrollPosition = Vector2.zero;
		}

		private void BanDelegate()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if (SelectedUser == null)
			{
				BepinPlugin.Log.LogWarning((object)"Attepted banning user while selected user was null.");
				return;
			}
			BepinPlugin.Log.LogInfo((object)("Banning user: " + SelectedUser.PlayerName));
			BanListManager.Instance.AddToBanlist(SelectedUser.SteamID, SelectedUser.PlayerName);
			if (PhotonNetwork.IsMasterClient)
			{
				Messaging.Echo("Banned user: " + SelectedUser.PlayerName, false);
				Game.Instance.KickPlayer(Game.Instance.GetPlayerCharacterByActorNumber(SelectedUser.PhotonPlayer.ActorNumber));
			}
			else
			{
				Messaging.Echo("Added user to local ban list: " + SelectedUser.PlayerName, true);
			}
		}
	}
	[BepInPlugin("SteamBanning", "SteamBanning", "1.0.0")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal class Bindings
		{
			internal static ConfigEntry<string> BanList;
		}

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Bindings.BanList = ((BaseUnityPlugin)this).Config.Bind<string>("General", "BanList", string.Empty, "Local Ban List. Formt: 'steamID:username'. Separate multiple instances with ','");
			BanListManager.Instance = new BanListManager();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin SteamBanning is loaded!");
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)3;

		public override string Author => "Dragon";

		public override string Description => "Provides banning feature to hosts.";

		public VoidManagerPlugin()
		{
			Events.Instance.PlayerEnteredRoom += BanListManager.Instance.OnPlayerJoin;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SteamBanning";

		public const string PLUGIN_NAME = "SteamBanning";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}