Decompiled source of Moderation Plus v0.1.1

moderationPlus.dll

Decompiled 2 weeks 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using Mirror;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigWalk-ModerationPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BigWalk-ModerationPlus")]
[assembly: AssemblyTitle("BigWalk-ModerationPlus")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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;
		}
	}
}
public static class thisisthebanstorepleasebuyanyban
{
	private static readonly string pathforbans = Path.Combine(Paths.PluginPath, "bayturtles-moderationplus-bans.txt");

	private static readonly HashSet<string> peoplebanned = new HashSet<string>();

	public static void load()
	{
		if (!File.Exists(pathforbans))
		{
			return;
		}
		string[] array = File.ReadAllLines(pathforbans);
		foreach (string text in array)
		{
			if (!string.IsNullOrWhiteSpace(text))
			{
				peoplebanned.Add(text.Trim());
			}
		}
	}

	public static void savebanss()
	{
		File.WriteAllLines(pathforbans, peoplebanned);
	}

	public static bool alreadybanned(string id)
	{
		if (!string.IsNullOrEmpty(id))
		{
			return peoplebanned.Contains(id);
		}
		return false;
	}

	public static void doban(string id)
	{
		if (!string.IsNullOrWhiteSpace(id))
		{
			peoplebanned.Add(id.Trim());
			savebanss();
		}
	}

	public static void getridofban(string id)
	{
		peoplebanned.Remove(id);
		savebanss();
	}

	public static IEnumerable<string> all()
	{
		return peoplebanned.OrderBy((string x) => x);
	}
}
public static class turtlesimpleanticheat
{
	private class followdata
	{
		public Vector3 posoflast;

		public float lastymovetime;

		public float lastypositiony;
	}

	public static bool enabled = false;

	public static float fastlimit = 15f;

	public static float limittobeinginair = 3f;

	public static List<string> modlogheythatrhymes = new List<string>();

	private static Dictionary<string, followdata> trackedplayersss = new Dictionary<string, followdata>();

	private static List<PlayerCharacter> registeredplayers = new List<PlayerCharacter>();

	public static void registerplayer(PlayerCharacter character)
	{
		if (!((Object)(object)character == (Object)null) && !registeredplayers.Contains(character))
		{
			registeredplayers.Add(character);
		}
	}

	public static void unregisterplayer(PlayerCharacter character)
	{
		if (!((Object)(object)character == (Object)null))
		{
			registeredplayers.Remove(character);
			PlayerNetworking playerNetworking = character.playerNetworking;
			if ((Object)(object)playerNetworking != (Object)null && !string.IsNullOrEmpty(playerNetworking.identifier))
			{
				trackedplayersss.Remove(playerNetworking.identifier);
			}
		}
	}

	public static void seedfromscene()
	{
		registeredplayers.Clear();
		foreach (PlayerCharacter item in Object.FindObjectsOfType<PlayerCharacter>())
		{
			registerplayer(item);
		}
	}

	public static IReadOnlyList<PlayerCharacter> getcharacters()
	{
		return registeredplayers;
	}

	public static void tick()
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: 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_00e1: 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)
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		if (!NetworkServer.active || Time.deltaTime <= 0f)
		{
			return;
		}
		for (int num = registeredplayers.Count - 1; num >= 0; num--)
		{
			PlayerCharacter val = registeredplayers[num];
			if ((Object)(object)val == (Object)null)
			{
				registeredplayers.RemoveAt(num);
				continue;
			}
			if (((NetworkBehaviour)val).isLocalPlayer)
			{
				continue;
			}
			PlayerNetworking playerNetworking = val.playerNetworking;
			if ((Object)(object)playerNetworking == (Object)null)
			{
				continue;
			}
			string identifier = playerNetworking.identifier;
			if (string.IsNullOrEmpty(identifier))
			{
				continue;
			}
			Vector3 position = ((Component)val).transform.position;
			if (!trackedplayersss.TryGetValue(identifier, out var value))
			{
				trackedplayersss[identifier] = new followdata
				{
					posoflast = position,
					lastymovetime = Time.time,
					lastypositiony = position.y
				};
				continue;
			}
			Vector2 val2 = new Vector2(position.x - value.posoflast.x, position.z - value.posoflast.z);
			float num2 = ((Vector2)(ref val2)).magnitude / Time.deltaTime;
			int num3;
			if (val.ground != null)
			{
				num3 = (val.ground.isGrounded ? 1 : 0);
				if (num3 != 0)
				{
					goto IL_0138;
				}
			}
			else
			{
				num3 = 0;
			}
			if (position.y < value.lastypositiony - 0.05f)
			{
				goto IL_0138;
			}
			goto IL_0152;
			IL_0138:
			value.lastymovetime = Time.time;
			value.lastypositiony = position.y;
			goto IL_0152;
			IL_0152:
			float num4 = Time.time - value.lastymovetime;
			bool flag = num3 == 0 && num4 > limittobeinginair;
			bool flag2 = num2 > fastlimit;
			if (enabled && (flag || flag2))
			{
				string text = (flag ? "aretheyflying" : "aretheyusingbigrun");
				makelogg(playerNetworking.username + " kicked for " + text);
				playerNetworking.RPCKickUser(((NetworkBehaviour)playerNetworking).connectionToClient);
				trackedplayersss.Remove(identifier);
			}
			else
			{
				value.posoflast = position;
			}
		}
	}

	private static void makelogg(string message)
	{
		modlogheythatrhymes.Insert(0, message);
		if (modlogheythatrhymes.Count > 50)
		{
			modlogheythatrhymes.RemoveAt(modlogheythatrhymes.Count - 1);
		}
	}
}
public class theuipart : MonoBehaviour
{
	private static ConfigEntry<KeyCode> togglekey;

	private static ConfigEntry<float> uiscale;

	private bool showui;

	private int tab;

	private Rect windowsizess = new Rect(60f, 60f, 480f, 360f);

	private Vector2 playerscrollthing;

	private Vector2 bannedscrollthing;

	private string banidmanua = "";

	public theuipart(IntPtr ptr)
		: base(ptr)
	{
	}//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)


	public static void init(ConfigFile config)
	{
		config.SaveOnConfigSet = false;
		togglekey = config.Bind<KeyCode>("general", "togglekey", (KeyCode)287, "key to show the mod panel");
		uiscale = config.Bind<float>("general", "uiscale", 1f, "scale of the moderation panel");
		thisisthebanstorepleasebuyanyban.load();
		turtlesimpleanticheat.seedfromscene();
	}

	private void Update()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(togglekey.Value))
		{
			showui = !showui;
			if (!showui)
			{
				((ConfigEntryBase)uiscale).ConfigFile.Save();
			}
		}
		turtlesimpleanticheat.tick();
	}

	private void OnGUI()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (showui)
		{
			Matrix4x4 matrix = GUI.matrix;
			GUIUtility.ScaleAroundPivot(new Vector2(uiscale.Value, uiscale.Value), ((Rect)(ref windowsizess)).position);
			windowsizess = GUI.Window(834112, windowsizess, WindowFunction.op_Implicit((Action<int>)makepanel), "BayTurtle's Moderation+");
			GUI.matrix = matrix;
		}
	}

	private void makepanel(int id)
	{
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		GUILayout.Label("ui scale", (Il2CppReferenceArray<GUILayoutOption>)null);
		uiscale.Value = GUILayout.HorizontalSlider(uiscale.Value, 0.6f, 2f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(140f) });
		GUILayout.Label(uiscale.Value.ToString("0.00"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) });
		GUILayout.EndHorizontal();
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		if (GUILayout.Toggle(tab == 0, "players", GUI.skin.button, (Il2CppReferenceArray<GUILayoutOption>)null))
		{
			tab = 0;
		}
		if (GUILayout.Toggle(tab == 1, "anti cheat", GUI.skin.button, (Il2CppReferenceArray<GUILayoutOption>)null))
		{
			tab = 1;
		}
		if (GUILayout.Toggle(tab == 2, "bans", GUI.skin.button, (Il2CppReferenceArray<GUILayoutOption>)null))
		{
			tab = 2;
		}
		GUILayout.EndHorizontal();
		if (tab == 0)
		{
			showplrs();
		}
		if (tab == 1)
		{
			makeanticheathing();
		}
		if (tab == 2)
		{
			showbanned();
		}
		GUI.DragWindow(new Rect(0f, 0f, ((Rect)(ref windowsizess)).width, 20f));
	}

	private void showplrs()
	{
		//IL_0002: 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_001f: Unknown result type (might be due to invalid IL or missing references)
		playerscrollthing = GUILayout.BeginScrollView(playerscrollthing, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(240f) });
		foreach (PlayerCharacter item in turtlesimpleanticheat.getcharacters())
		{
			if ((Object)(object)item == (Object)null || ((NetworkBehaviour)item).isLocalPlayer)
			{
				continue;
			}
			PlayerNetworking playerNetworking = item.playerNetworking;
			if ((Object)(object)playerNetworking == (Object)null)
			{
				continue;
			}
			string identifier = playerNetworking.identifier;
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.Label(playerNetworking.username + " (" + identifier + ")", (Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("kick", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
			{
				playerNetworking.RPCKickUser(((NetworkBehaviour)playerNetworking).connectionToClient);
			}
			if (thisisthebanstorepleasebuyanyban.alreadybanned(identifier))
			{
				if (GUILayout.Button("unban", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) }))
				{
					thisisthebanstorepleasebuyanyban.getridofban(identifier);
				}
			}
			else if (GUILayout.Button("ban", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }))
			{
				thisisthebanstorepleasebuyanyban.doban(identifier);
				playerNetworking.RPCKickUser(((NetworkBehaviour)playerNetworking).connectionToClient);
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.EndScrollView();
	}

	private void makeanticheathing()
	{
		turtlesimpleanticheat.enabled = GUILayout.Toggle(turtlesimpleanticheat.enabled, "flying/speed hack autokick", Array.Empty<GUILayoutOption>());
		GUILayout.Label("max speed before detected as speed hack: " + turtlesimpleanticheat.fastlimit.ToString("0.0"), (Il2CppReferenceArray<GUILayoutOption>)null);
		turtlesimpleanticheat.fastlimit = GUILayout.HorizontalSlider(turtlesimpleanticheat.fastlimit, 3f, 40f, Array.Empty<GUILayoutOption>());
		GUILayout.Label("max airtime before detected as flying : " + turtlesimpleanticheat.limittobeinginair.ToString("0.0") + "s", (Il2CppReferenceArray<GUILayoutOption>)null);
		turtlesimpleanticheat.limittobeinginair = GUILayout.HorizontalSlider(turtlesimpleanticheat.limittobeinginair, 1f, 10f, Array.Empty<GUILayoutOption>());
		GUILayout.Label("recently kicked/found:", (Il2CppReferenceArray<GUILayoutOption>)null);
		foreach (string modlogheythatrhyme in turtlesimpleanticheat.modlogheythatrhymes)
		{
			GUILayout.Label(modlogheythatrhyme, (Il2CppReferenceArray<GUILayoutOption>)null);
		}
	}

	private void showbanned()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
		banidmanua = GUILayout.TextField(banidmanua, (Il2CppReferenceArray<GUILayoutOption>)null);
		if (GUILayout.Button("ban", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) }))
		{
			thisisthebanstorepleasebuyanyban.doban(banidmanua);
			banidmanua = "";
		}
		GUILayout.EndHorizontal();
		bannedscrollthing = GUILayout.BeginScrollView(bannedscrollthing, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(240f) });
		foreach (string item in thisisthebanstorepleasebuyanyban.all())
		{
			GUILayout.BeginHorizontal((Il2CppReferenceArray<GUILayoutOption>)null);
			GUILayout.Label(item, (Il2CppReferenceArray<GUILayoutOption>)null);
			if (GUILayout.Button("unban", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(55f) }))
			{
				thisisthebanstorepleasebuyanyban.getridofban(item);
			}
			GUILayout.EndHorizontal();
		}
		GUILayout.EndScrollView();
	}
}
[HarmonyPatch(typeof(PlayerNetworking), "OnSetIdentifier")]
public static class banemm
{
	private static void Postfix(PlayerNetworking __instance, string valold, string valnew)
	{
		if (NetworkServer.active && !string.IsNullOrEmpty(valnew) && thisisthebanstorepleasebuyanyban.alreadybanned(valnew))
		{
			__instance.RPCKickUser(((NetworkBehaviour)__instance).connectionToClient);
		}
	}
}
[HarmonyPatch(typeof(PlayerNetworking), "OnStartClient")]
public static class trackwhentheyjoin
{
	private static void Postfix(PlayerNetworking __instance)
	{
		PlayerCharacter val = ((Component)__instance).GetComponent<PlayerCharacter>();
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)__instance).GetComponentInParent<PlayerCharacter>();
		}
		turtlesimpleanticheat.registerplayer(val);
	}
}
[HarmonyPatch(typeof(PlayerNetworking), "OnStopClient")]
public static class andtrackwhentheyleavee
{
	private static void Postfix(PlayerNetworking __instance)
	{
		PlayerCharacter val = ((Component)__instance).GetComponent<PlayerCharacter>();
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)__instance).GetComponentInParent<PlayerCharacter>();
		}
		turtlesimpleanticheat.unregisterplayer(val);
	}
}
[BepInPlugin("bayturtleking.moderationpluss", "Moderation+", "1.0.0")]
public class plugin : BasePlugin
{
	internal static ManualLogSource modlogheythatrhymes;

	public override void Load()
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Expected O, but got Unknown
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		modlogheythatrhymes = ((BasePlugin)this).Log;
		ClassInjector.RegisterTypeInIl2Cpp<theuipart>();
		theuipart.init(((BasePlugin)this).Config);
		GameObject val = new GameObject("moderationtoolsholder");
		Object.DontDestroyOnLoad((Object)val);
		val.AddComponent<theuipart>();
		new Harmony("bayturtleking.moderationpluss").PatchAll();
		modlogheythatrhymes.LogInfo((object)"moderationplus by bayturtle loaded");
	}
}