Decompiled source of LethalCloudBan v1.0.0

LethalCloudBan.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LobbyImprovements;
using Microsoft.CodeAnalysis;
using Netcode.Transports.Facepunch;
using Newtonsoft.Json;
using Steamworks.Data;
using Unity.Netcode;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("com.olegknyazev.softmask")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("EasyTextEffects")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[assembly: IgnoresAccessChecksTo("uk.1a3.lobbyimprovements")]
[assembly: IgnoresAccessChecksTo("Unity.AI.Navigation")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging")]
[assembly: IgnoresAccessChecksTo("Unity.Animation.Rigging.DocCodeExamples")]
[assembly: IgnoresAccessChecksTo("Unity.Burst")]
[assembly: IgnoresAccessChecksTo("Unity.Burst.Unsafe")]
[assembly: IgnoresAccessChecksTo("Unity.Collections")]
[assembly: IgnoresAccessChecksTo("Unity.Collections.LowLevel.ILSupport")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem")]
[assembly: IgnoresAccessChecksTo("Unity.InputSystem.ForUI")]
[assembly: IgnoresAccessChecksTo("Unity.Jobs")]
[assembly: IgnoresAccessChecksTo("Unity.Mathematics")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.Common")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.MetricTypes")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStats")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Component")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsMonitor.Implementation")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetStatsReporting")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkProfiler.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Multiplayer.Tools.NetworkSolutionInterface")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.Networking.Transport")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Csg")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.KdTree")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Poly2Tri")]
[assembly: IgnoresAccessChecksTo("Unity.ProBuilder.Stl")]
[assembly: IgnoresAccessChecksTo("Unity.Profiling.Core")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Core.ShaderLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Config.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.HighDefinition.Runtime")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.ShaderGraph.ShaderGraphLibrary")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Authentication")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Analytics")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Components")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Configuration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Device")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Environments.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Internal")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Networking")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Registration")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Scheduler")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Telemetry")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Core.Threading")]
[assembly: IgnoresAccessChecksTo("Unity.Services.QoS")]
[assembly: IgnoresAccessChecksTo("Unity.Services.Relay")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("Unity.Timeline")]
[assembly: IgnoresAccessChecksTo("Unity.VisualEffectGraph.Runtime")]
[assembly: IgnoresAccessChecksTo("UnityEngine.ARModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.NVIDIAModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("chuxiaaaa")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("LethalCloudBan")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+4754aadea706fc63b7ae0280000ed4997e7c8218")]
[assembly: AssemblyProduct("LethalCloudBan")]
[assembly: AssemblyTitle("LethalCloudBan")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
internal static class LCMPluginInfo
{
	public const string PLUGIN_GUID = "LethalCloudBan";

	public const string PLUGIN_NAME = "LethalCloudBan";

	public const string PLUGIN_VERSION = "1.0.0";
}
namespace LethalMod
{
	[BepInPlugin("LethalCloudBan", "LethalCloudBan", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static BlacklistApiClient Client;

		public static ManualLogSource ManualLog;

		public static ConfigEntry<string> ServerIp;

		public void Awake()
		{
			ManualLog = ((BaseUnityPlugin)this).Logger;
			ServerIp = ((BaseUnityPlugin)this).Config.Bind<string>("Server", "IP", "http://localhost:6179", (ConfigDescription)null);
			HttpClient httpClient = new HttpClient();
			httpClient.Timeout = TimeSpan.FromSeconds(3.0);
			Client = new BlacklistApiClient(httpClient);
			Harmony.CreateAndPatchAll(typeof(Patches), (string)null);
		}
	}
	public static class Patches
	{
		public static Dictionary<uint, ulong> ConnectionIdtoSteamIdMap { get; set; } = new Dictionary<uint, ulong>();


		public static uint ClientIdToTransportId(ulong SenderClientId)
		{
			if (SenderClientId == 0)
			{
				return 0u;
			}
			NetworkConnectionManager value = Traverse.Create((object)NetworkManager.Singleton).Field("ConnectionManager").GetValue<NetworkConnectionManager>();
			ulong value2 = Traverse.Create((object)value).Method("ClientIdToTransportId", new object[1] { SenderClientId }).GetValue<ulong>();
			return (uint)value2;
		}

		[HarmonyPatch(typeof(FacepunchTransport), "Steamworks.ISocketManager.OnConnecting")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static bool FacepunchTransportOnConnecting(ref Connection connection, ref ConnectionInfo info)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			NetIdentity value = Traverse.Create((object)info).Field<NetIdentity>("identity").Value;
			if (ConnectionIdtoSteamIdMap.ContainsKey(((Connection)(ref connection)).Id))
			{
				ConnectionIdtoSteamIdMap[((Connection)(ref connection)).Id] = ((NetIdentity)(ref value)).SteamId.Value;
			}
			else
			{
				ConnectionIdtoSteamIdMap.Add(((Connection)(ref connection)).Id, ((NetIdentity)(ref value)).SteamId.Value);
			}
			return true;
		}

		[HarmonyPatch(typeof(FacepunchTransport), "Steamworks.ISocketManager.OnDisconnected")]
		[HarmonyPrefix]
		[HarmonyWrapSafe]
		public static void FacepunchTransportOnDisconnected(ref Connection connection, ref ConnectionInfo info)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if (singleton != null && singleton.IsListening)
			{
				NetIdentity value = Traverse.Create((object)info).Field<NetIdentity>("identity").Value;
				ConnectionIdtoSteamIdMap.Remove(((Connection)(ref connection)).Id);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "ConnectionApproval")]
		[HarmonyWrapSafe]
		[HarmonyPriority(0)]
		[HarmonyAfter(new string[] { "mattymatty.LobbyControl" })]
		private static void Postfix(ConnectionApprovalRequest request, ConnectionApprovalResponse response)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (request.ClientNetworkId != 0)
			{
				ulong num = ConnectionIdtoSteamIdMap[ClientIdToTransportId(request.ClientNetworkId)];
				List<BlacklistItem> byValue = Plugin.Client.GetByValue(num.ToString());
				if (byValue != null && byValue != null && byValue.Count > 0)
				{
					response.Approved = false;
					response.Reason = "你已被加入云端黑名单\r\n原因:" + byValue[0].Reason + "\r\n如需申诉请加Q群:\r\n1090975552";
				}
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StartOfRound), "KickPlayer")]
		public static void KickPlayer(int playerObjToKick)
		{
			ulong playerSteamId = StartOfRound.Instance.allPlayerScripts[playerObjToKick].playerSteamId;
			if (General_Patches.steamBanReasons.ContainsKey(playerSteamId))
			{
				Plugin.Client.Add(new BlacklistItem
				{
					BlackValue = playerSteamId.ToString(),
					Reason = General_Patches.steamBanReasons[playerSteamId],
					CreatedTime = DateTime.Now,
					Creator = StartOfRound.Instance.localPlayerController.playerSteamId.ToString(),
					Id = Guid.NewGuid(),
					IsActive = true
				});
			}
		}
	}
	public class BlacklistItem
	{
		public Guid Id { get; set; }

		public string Creator { get; set; }

		public string Key { get; set; }

		public DateTime CreatedTime { get; set; }

		public string Reason { get; set; }

		public string BlackValue { get; set; }

		public bool IsActive { get; set; }
	}
	public class BlacklistApiClient
	{
		private readonly HttpClient _httpClient;

		private readonly string _baseUrl = Plugin.ServerIp.Value + "/api/blacklist";

		public BlacklistApiClient(HttpClient httpClient)
		{
			_httpClient = httpClient;
		}

		public List<BlacklistItem> GetByValue(string value)
		{
			string address = _baseUrl + "/by-value?blackValue=" + Uri.EscapeDataString(value);
			using WebClient webClient = new WebClient();
			webClient.Encoding = Encoding.UTF8;
			string text = webClient.DownloadString(address);
			return JsonConvert.DeserializeObject<List<BlacklistItem>>(text);
		}

		public void Add(BlacklistItem item)
		{
			string text = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\LethalCloudBanKey.txt";
			bool flag = File.Exists(text);
			Plugin.ManualLog.LogInfo((object)$"keyPath:{text}|hasKey:{flag}");
			if (flag)
			{
				item.Key = File.ReadAllText(text);
				using WebClient webClient = new WebClient();
				webClient.Encoding = Encoding.UTF8;
				webClient.Headers[HttpRequestHeader.ContentType] = "application/json";
				string data = JsonConvert.SerializeObject((object)item);
				webClient.UploadString(_baseUrl, "POST", data);
			}
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}