Decompiled source of Disintegration v1.0.0

BepInEx/plugins/xilo.Disintegration.dll

Decompiled 10 months ago
using System;
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.Bootstrap;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.ProBuilder;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("AmazingAssets.TerrainToMesh")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("ClientNetworkTransform")]
[assembly: IgnoresAccessChecksTo("DissonanceVoip")]
[assembly: IgnoresAccessChecksTo("Facepunch Transport for Netcode for GameObjects")]
[assembly: IgnoresAccessChecksTo("Facepunch.Steamworks.Win64")]
[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.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: AssemblyCompany("xilo.Disintegration")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("What's wrong with return false prefixes?")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+99297212f610144d6df6b45b05a737c3bc5cf010")]
[assembly: AssemblyProduct("Disintegration")]
[assembly: AssemblyTitle("xilo.Disintegration")]
[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.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;
		}
	}
	[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 Disintegration
{
	[BepInPlugin("xilo.Disintegration", "Disintegration", "1.0.0")]
	public class Disintegration : BaseUnityPlugin
	{
		private static readonly Harmony RouletteHarmony = new Harmony("xilo.Disintegration.Roulette");

		private static Harmony? _harmony;

		private static GameObject _rouletteWheelObject = null;

		private static readonly HarmonyMethod PrefixMethod = new HarmonyMethod(typeof(Disintegration), "Prefix", (Type[])null);

		public static Disintegration Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		private void Awake()
		{
			//IL_0016: 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_0028: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			_rouletteWheelObject = new GameObject("RouletteWheel")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)(object)_rouletteWheelObject);
			_rouletteWheelObject.SetActive(false);
			_rouletteWheelObject.AddComponent<RouletteWheel>();
			Patch();
			Logger.LogInfo((object)"xilo.Disintegration v1.0.0 has loaded!");
		}

		private static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			if (_harmony == null)
			{
				_harmony = new Harmony("xilo.Disintegration");
			}
			Logger.LogDebug((object)"Patching...");
			_harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void RoulettePatch(MethodInfo methodInfo)
		{
			try
			{
				RouletteHarmony.Patch((MethodBase)methodInfo, PrefixMethod, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			catch (Exception)
			{
			}
		}

		internal static void EnableRoulette()
		{
			_rouletteWheelObject.SetActive(true);
		}

		internal static void DisableRoulette()
		{
			_rouletteWheelObject.SetActive(false);
			RouletteHarmony.UnpatchSelf();
		}

		private static bool Prefix()
		{
			return false;
		}
	}
	internal static class NetworkMessageHandler
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__ReceivePing;

			public static HandleNamedMessageDelegate <1>__ReceiveMethodMessage;
		}

		private const string PingMessage = "xilo.Disintegration.Ping";

		private const string MethodMessage = "xilo.Disintegration.Methods";

		internal static void Start()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			CustomMessagingManager customMessagingManager = NetworkManager.Singleton.CustomMessagingManager;
			object obj = <>O.<0>__ReceivePing;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = ReceivePing;
				<>O.<0>__ReceivePing = val;
				obj = (object)val;
			}
			customMessagingManager.RegisterNamedMessageHandler("xilo.Disintegration.Ping", (HandleNamedMessageDelegate)obj);
			CustomMessagingManager customMessagingManager2 = NetworkManager.Singleton.CustomMessagingManager;
			object obj2 = <>O.<1>__ReceiveMethodMessage;
			if (obj2 == null)
			{
				HandleNamedMessageDelegate val2 = ReceiveMethodMessage;
				<>O.<1>__ReceiveMethodMessage = val2;
				obj2 = (object)val2;
			}
			customMessagingManager2.RegisterNamedMessageHandler("xilo.Disintegration.Methods", (HandleNamedMessageDelegate)obj2);
		}

		internal static void Disconnect()
		{
			NetworkManager.Singleton.CustomMessagingManager.UnregisterNamedMessageHandler("xilo.Disintegration.Ping");
			NetworkManager.Singleton.CustomMessagingManager.UnregisterNamedMessageHandler("xilo.Disintegration.Methods");
		}

		private static void ReceivePing(ulong client, FastBufferReader _)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsServer)
			{
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("xilo.Disintegration.Ping", client, default(FastBufferWriter), (NetworkDelivery)3);
				FastBufferWriter writer = default(FastBufferWriter);
				((FastBufferWriter)(ref writer))..ctor(8196, (Allocator)2, -1);
				MethodInfo[] array = RouletteWheel.DisabledMethods ?? Array.Empty<MethodInfo>();
				foreach (MethodInfo methodInfo in array)
				{
					SerializeMethod(ref writer, methodInfo);
				}
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("xilo.Disintegration.Methods", client, writer, (NetworkDelivery)4);
			}
			else
			{
				Disintegration.DisableRoulette();
			}
		}

		private static void ReceiveMethodMessage(ulong client, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValue<int>(ref num, default(ForPrimitives));
			string text = default(string);
			string text2 = default(string);
			for (int i = 0; i < num; i++)
			{
				((FastBufferReader)(ref reader)).ReadValue(ref text, false);
				((FastBufferReader)(ref reader)).ReadValue(ref text2, false);
				Disintegration.RoulettePatch(AccessTools.Method(AccessTools.TypeByName(text), text2, (Type[])null, (Type[])null));
			}
			((FastBufferReader)(ref reader)).Dispose();
		}

		private static void SerializeMethod(ref FastBufferWriter writer, MemberInfo methodInfo)
		{
			((FastBufferWriter)(ref writer)).WriteValue(methodInfo.DeclaringType.FullName, false);
			((FastBufferWriter)(ref writer)).WriteValue(methodInfo.Name, false);
		}

		internal static void SendMethodToDisable(MemberInfo methodInfo)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsServer)
			{
				FastBufferWriter writer = default(FastBufferWriter);
				((FastBufferWriter)(ref writer))..ctor(1024, (Allocator)2, -1);
				SerializeMethod(ref writer, methodInfo);
				NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("xilo.Disintegration.Methods", NetworkManager.Singleton.ConnectedClientsIds, writer, (NetworkDelivery)3);
			}
		}

		internal static void PingServer()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("xilo.Disintegration.Ping", 0uL, default(FastBufferWriter), (NetworkDelivery)3);
		}
	}
	public class RouletteWheel : MonoBehaviour
	{
		private double _timeUntilChop;

		private static Random _random = null;

		private static readonly MethodInfo[] BlacklistFromRoulette = new MethodInfo[6]
		{
			AccessTools.Method(typeof(GameNetworkManager), "Disconnect", (Type[])null, (Type[])null),
			AccessTools.Method(typeof(GameNetworkManager), "OnApplicationQuit", (Type[])null, (Type[])null),
			AccessTools.Method(typeof(QuickMenuManager), "LeaveGame", (Type[])null, (Type[])null),
			AccessTools.Method(typeof(QuickMenuManager), "LeaveGameConfirm", (Type[])null, (Type[])null),
			AccessTools.Method(typeof(QuickMenuManager), "OpenQuickMenu", (Type[])null, (Type[])null),
			AccessTools.Method(typeof(PlayerControllerB), "OpenMenu_performed", (Type[])null, (Type[])null)
		};

		internal static MethodInfo[]? EnabledMethods;

		internal static MethodInfo[]? DisabledMethods;

		private void OnEnable()
		{
			_random = new Random();
			_timeUntilChop = _random.Next(2, 15);
			EnabledMethods = (from methodInfo in ArrayUtility.AddRange<MethodInfo>((from type in AccessTools.GetTypesFromAssembly(Assembly.GetAssembly(typeof(RoundManager)))
					select type.GetMethods(AccessTools.allDeclared)).SelectMany((MethodInfo[] method) => method).ToArray(), Chainloader.PluginInfos.Values.Where((PluginInfo info) => info.Metadata.GUID != "xilo.Disintegration").SelectMany((PluginInfo info) => (from type in AccessTools.GetTypesFromAssembly(((object)info.Instance).GetType().Assembly)
					select type.GetMethods(AccessTools.allDeclared)).SelectMany((MethodInfo[] method) => method)).ToArray())
				where !BlacklistFromRoulette.Any((MethodInfo blacklistedMethod) => blacklistedMethod.Equals(methodInfo))
				select methodInfo into _
				orderby _random.Next()
				select _).ToArray();
			DisabledMethods = Array.Empty<MethodInfo>();
		}

		private void OnDisable()
		{
			EnabledMethods = (DisabledMethods = Array.Empty<MethodInfo>());
		}

		private void FixedUpdate()
		{
			MethodInfo[] enabledMethods = EnabledMethods;
			if ((enabledMethods == null || enabledMethods.Length == 0) ? true : false)
			{
				((Component)this).gameObject.SetActive(false);
				return;
			}
			if (_timeUntilChop > 0.0)
			{
				_timeUntilChop -= Time.fixedDeltaTime;
				return;
			}
			_timeUntilChop = _random.Next(4, 18);
			Disintegration.RoulettePatch(EnabledMethods[0]);
			NetworkManager singleton = NetworkManager.Singleton;
			if (singleton != null && singleton.IsServer)
			{
				NetworkMessageHandler.SendMethodToDisable(EnabledMethods[0]);
			}
			CollectionExtensions.AddToArray<MethodInfo>(DisabledMethods, EnabledMethods[0]);
			EnabledMethods = ArrayUtility.RemoveAt<MethodInfo>(EnabledMethods, 0);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "xilo.Disintegration";

		public const string PLUGIN_NAME = "Disintegration";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace Disintegration.Patches
{
	[HarmonyPatch]
	[HarmonyWrapSafe]
	internal class GameNetworkManagerPatches
	{
		[HarmonyPatch(typeof(GameNetworkManager), "StartHost")]
		[HarmonyPostfix]
		private static void StartHost()
		{
			Disintegration.EnableRoulette();
		}

		[HarmonyPatch(typeof(GameNetworkManager), "StartClient")]
		[HarmonyPostfix]
		private static void StartClient()
		{
			Disintegration.EnableRoulette();
			NetworkMessageHandler.PingServer();
		}

		[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
		[HarmonyPostfix]
		private static void Disconnect()
		{
			Disintegration.DisableRoulette();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}