Decompiled source of ModerationMenu v1.0.0

ModerationMenu.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using GameNetcodeStuff;
using HarmonyLib;
using MelonLoader;
using ModerationMenu;
using ModerationMenu.Menu;
using ModerationMenu.Players;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MainEntry), "ModerationMenu", "1.0.0", "LostAdmiration", null)]
[assembly: AssemblyTitle("UnwantedCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("UnwantedCompany")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("acd6398c-70af-4095-9ffb-cde1f483bd36")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ModerationMenu
{
	public class LocalPlayer
	{
		public static LocalPlayer localPlayer;

		public PlayerControllerB PlayerController { get; set; }

		public int Health { get; set; }

		public LocalPlayer(PlayerControllerB playerController)
		{
			PlayerController = playerController;
		}

		public static bool IsValid()
		{
			if (localPlayer != null && (Object)(object)localPlayer.PlayerController != (Object)null && (Object)(object)((Component)localPlayer.PlayerController).gameObject != (Object)null && (Object)(object)((Component)localPlayer.PlayerController).gameObject.GetComponent<PlayerControllerB>() != (Object)null)
			{
				return ((Component)localPlayer.PlayerController).gameObject.GetComponent<PlayerControllerB>().isPlayerControlled;
			}
			return false;
		}
	}
	public class MainEntry : MelonMod
	{
		public static PlayerManager _playerManager;

		private Rect windowRect = new Rect(10f, 10f, 200f, 200f);

		private Rect player_windowRect = new Rect(10f, 10f, 200f, 200f);

		private MenuClass _menu;

		private List<Collider> disabledColliders = new List<Collider>();

		public override void OnApplicationStart()
		{
			_playerManager = new PlayerManager();
			_menu = new MenuClass();
		}

		public override void OnLateUpdate()
		{
			if (((ButtonControl)Keyboard.current[(Key)70]).wasPressedThisFrame)
			{
				Settings.Instance.menuOpen = !Settings.Instance.menuOpen;
			}
		}

		public override void OnUpdate()
		{
			_playerManager.UpdatePlayers();
		}

		public override void OnGUI()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0063: 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)
			if (Settings.Instance.menuOpen)
			{
				windowRect = GUILayout.Window(1, windowRect, new WindowFunction(_menu.DrawMenu), "Moderation Menu", Array.Empty<GUILayoutOption>());
				if (Settings.Instance.showPlayerMenu)
				{
					player_windowRect = GUILayout.Window(2, player_windowRect, new WindowFunction(DrawPlayerMenu), "Player Menu", Array.Empty<GUILayoutOption>());
				}
			}
		}

		[HarmonyPatch(typeof(NetworkManager), "DisconnectClient")]
		private void DrawPlayerMenu(int windowID)
		{
			if ((Object)(object)Settings.Instance.selectedPlayer != (Object)null)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				GUILayout.FlexibleSpace();
				if (GUILayout.Button("X", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) }))
				{
					Settings.Instance.showPlayerMenu = false;
					return;
				}
				GUILayout.EndHorizontal();
				GUILayout.Label("Player: " + Settings.Instance.selectedPlayer.playerUsername, Array.Empty<GUILayoutOption>());
				if (GUILayout.Button("Open Steam Profile ->: " + Settings.Instance.selectedPlayer.playerSteamId, Array.Empty<GUILayoutOption>()))
				{
					Application.OpenURL("https://steamcommunity.com/profiles/" + Settings.Instance.selectedPlayer.playerSteamId);
				}
				if (GUILayout.Button("Kick *(Host)", Array.Empty<GUILayoutOption>()))
				{
					Object.FindObjectOfType<NetworkManager>().DisconnectClient(Settings.Instance.selectedPlayer.playerClientId, "You have been Permanently Banned From This server");
				}
			}
			GUI.DragWindow();
		}
	}
	public class Settings
	{
		public PlayerControllerB selectedPlayer;

		public bool showPlayerMenu;

		public bool menuOpen;

		private static Settings instance;

		public static Settings Instance
		{
			get
			{
				if (instance == null)
				{
					instance = new Settings();
				}
				return instance;
			}
		}
	}
}
namespace ModerationMenu.Players
{
	public class PlayerManager
	{
		private List<PlayerControllerB> _players;

		public PlayerManager()
		{
			_players = new List<PlayerControllerB>();
		}

		public void UpdatePlayers()
		{
			_players.Clear();
			if (!LocalPlayer.IsValid())
			{
				PlayerControllerB[] array = Object.FindObjectsOfType<PlayerControllerB>();
				foreach (PlayerControllerB val in array)
				{
					if ((Object)(object)val != (Object)null && ((Component)val).gameObject.GetComponent<PlayerControllerB>().isPlayerControlled && ((NetworkBehaviour)val).IsOwner)
					{
						LocalPlayer.localPlayer = new LocalPlayer(val);
						break;
					}
				}
			}
			_players.AddRange(Object.FindObjectsOfType<PlayerControllerB>());
			_players.RemoveAll((PlayerControllerB player) => !IsValidPlayer(player));
		}

		public IEnumerable<PlayerControllerB> GetPlayers()
		{
			return _players;
		}

		private bool IsValidPlayer(PlayerControllerB player)
		{
			if ((Object)(object)player == (Object)null || (Object)(object)player == (Object)(object)LocalPlayer.localPlayer.PlayerController)
			{
				return false;
			}
			if ((Object)(object)((Component)player).gameObject == (Object)null || (Object)(object)((Component)player).gameObject.GetComponent<PlayerControllerB>() == (Object)null)
			{
				return false;
			}
			if (player.playerSteamId == 0L)
			{
				return false;
			}
			return true;
		}
	}
}
namespace ModerationMenu.Menu
{
	public class MenuClass
	{
		public void DrawMenu(int windowID)
		{
			if (!Settings.Instance.menuOpen)
			{
				return;
			}
			GUILayout.Label("Players:", Array.Empty<GUILayoutOption>());
			int num = 5;
			int num2 = 0;
			foreach (PlayerControllerB player in MainEntry._playerManager.GetPlayers())
			{
				if (num2 % num == 0)
				{
					if (num2 > 0)
					{
						GUILayout.EndHorizontal();
					}
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				}
				if (GUILayout.Button(player.playerUsername, Array.Empty<GUILayoutOption>()))
				{
					Settings.Instance.selectedPlayer = player;
					Settings.Instance.showPlayerMenu = true;
				}
				num2++;
			}
			if (num2 > 0)
			{
				GUILayout.EndHorizontal();
			}
			GUI.DragWindow();
		}
	}
}