Decompiled source of Garbage Disposal Testbed v0.0.6

Garbage_Disposal_Testbed.dll

Decompiled 2 years ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using GTFO.API;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using SNetwork;
using SNetwork_Transport;
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("NetworkCompression")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NetworkCompression")]
[assembly: AssemblyTitle("NetworkCompression")]
[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;
		}
	}
}
namespace NetworkCompression
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("NetworkCompression", "NetworkCompression", "0.0.6")]
	public class Plugin : BasePlugin
	{
		public struct CompressNetInfo
		{
			public int C;

			public ulong SENDER;

			public static string NetworkIdentity => "CompressNetInfo";

			public CompressNetInfo(int c, ulong SENDER)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Expected O, but got Unknown
				this = default(CompressNetInfo);
				C = c;
				ManualLogSource? log = NetworkCompression.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NetworkCompression PING ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(c);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ulong>(SENDER);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ..");
				}
				log.LogInfo(val);
			}
		}

		public struct CompressInfo
		{
			public int C;

			private ulong SENDER;

			public CompressInfo(int c, ulong sender)
			{
				this = default(CompressInfo);
				C = c;
				SENDER = sender;
			}

			public CompressInfo(CompressNetInfo network)
			{
				this = default(CompressInfo);
				C = network.C;
				SENDER = network.SENDER;
			}
		}

		public class NetworkCompression : MonoBehaviour
		{
			public static ManualLogSource? Log;

			public static List<SNet_Player> compressed = new List<SNet_Player>();

			public static uint OrigSize = 1u;

			public static uint CompSize = 1u;

			public static void Initialize()
			{
				compressed.Clear();
				Log.LogInfo((object)"setting up network compression");
				CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(Reveal()), (Action)null);
			}

			private static IEnumerator Reveal()
			{
				int laskuri = 0;
				bool flag = default(bool);
				while (true)
				{
					laskuri++;
					float num = (1 - CompSize / OrigSize) * 100;
					int c = 1;
					NetworkAPI.InvokeEvent<CompressNetInfo>("CompressNetInfo", new CompressNetInfo(c, 0uL), (SNet_ChannelType)2);
					ManualLogSource? log = Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 3, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("PING! stats: orig ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(OrigSize);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" compressed ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(CompSize);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" savings: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" .. ");
					}
					log.LogInfo(val);
					yield return (object)new WaitForSeconds(5f);
				}
			}

			public static void ReceiveCompressNetInfo(ulong sender, CompressNetInfo netInfo)
			{
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Expected O, but got Unknown
				bool flag = false;
				SNet_Player val = default(SNet_Player);
				SNet.TryGetPlayer(sender, ref val);
				foreach (SNet_Player item in compressed)
				{
					if ((Object)(object)item == (Object)(object)val)
					{
						flag = true;
					}
				}
				if (flag)
				{
					return;
				}
				bool flag2 = default(bool);
				if (netInfo.C == 1)
				{
					ManualLogSource? log = Log;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("PING from ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" id ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ulong>(sender);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", enabling compression ..");
					}
					log.LogInfo(val2);
					int c = 2;
					NetworkAPI.InvokeEvent<CompressNetInfo>("CompressNetInfo", new CompressNetInfo(c, sender), (SNet_ChannelType)2);
					compressed.Add(val);
				}
				if (netInfo.C == 2)
				{
					if (SNet.LocalPlayer.Lookup == netInfo.SENDER)
					{
						compressed.Add(val);
					}
					ManualLogSource? log2 = Log;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(39, 2, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("PONG from ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)val).name);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" id ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<ulong>(sender);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(", enabling compression ..");
					}
					log2.LogInfo(val2);
				}
			}
		}

		[HarmonyPatch]
		private abstract class NetworkCompression_Patches
		{
			[HarmonyPrefix]
			[HarmonyPatch(typeof(SNet_Core), "SendBytes", new Type[]
			{
				typeof(Il2CppStructArray<byte>),
				typeof(SNet_SendQuality),
				typeof(int),
				typeof(SNet_Player)
			})]
			public static void SendBytes(SNet_Core __instance, ref byte[] bytes, SNet_SendQuality quality, int channel, SNet_Player toPlayer)
			{
				NetworkCompression.OrigSize += (uint)bytes.Length;
				MemoryStream memoryStream = new MemoryStream(bytes);
				MemoryStream memoryStream2 = new MemoryStream();
				using (GZipStream destination = new GZipStream(memoryStream2, CompressionMode.Compress))
				{
					memoryStream.CopyTo(destination);
				}
				byte[] array = memoryStream2.ToArray();
				NetworkCompression.CompSize += (uint)array.Length;
				bytes = array;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(SNet_Core), "SendBytes", new Type[]
			{
				typeof(Il2CppStructArray<byte>),
				typeof(SNet_SendQuality),
				typeof(int),
				typeof(List<SNet_Player>)
			})]
			public static void SendBytes(SNet_Core __instance, ref byte[] bytes, SNet_SendQuality quality, int channel, List<SNet_Player> toPlayers)
			{
				NetworkCompression.OrigSize += (uint)bytes.Length;
				MemoryStream memoryStream = new MemoryStream(bytes);
				MemoryStream memoryStream2 = new MemoryStream();
				using (GZipStream destination = new GZipStream(memoryStream2, CompressionMode.Compress))
				{
					memoryStream.CopyTo(destination);
				}
				byte[] array = memoryStream2.ToArray();
				NetworkCompression.CompSize += (uint)array.Length;
				bytes = array;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(SNet_Core), "SendBytes", new Type[]
			{
				typeof(Il2CppStructArray<byte>),
				typeof(SNet_SendGroup),
				typeof(SNet_SendQuality),
				typeof(int)
			})]
			public static void SendBytes(SNet_Core __instance, ref byte[] bytes, SNet_SendGroup style, SNet_SendQuality quality, int channel)
			{
				NetworkCompression.OrigSize += (uint)bytes.Length;
				MemoryStream memoryStream = new MemoryStream(bytes);
				MemoryStream memoryStream2 = new MemoryStream();
				using (GZipStream destination = new GZipStream(memoryStream2, CompressionMode.Compress))
				{
					memoryStream.CopyTo(destination);
				}
				byte[] array = memoryStream2.ToArray();
				NetworkCompression.CompSize += (uint)array.Length;
				bytes = array;
			}

			[HarmonyPrefix]
			[HarmonyPatch(typeof(SNetTransport), "Receive")]
			public static void Receive(SNetTransport __instance, ref byte[] bytes, ref int size)
			{
				if (bytes.Length != 0)
				{
					SNet_Player val = default(SNet_Player);
					SNet.Replication.TryGetLastSender(ref val, false);
					GZipStream gZipStream = new GZipStream(new MemoryStream(bytes), CompressionMode.Decompress);
					MemoryStream memoryStream = new MemoryStream();
					gZipStream.CopyTo(memoryStream);
					bytes = memoryStream.ToArray();
					size = bytes.Length;
				}
			}
		}

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("NetworkCompression").PatchAll();
			((BasePlugin)this).AddComponent<NetworkCompression>();
			NetworkCompression.Log = ((BasePlugin)this).Log;
			NetworkAPI.RegisterEvent<CompressNetInfo>(CompressNetInfo.NetworkIdentity, (Action<ulong, CompressNetInfo>)NetworkCompression.ReceiveCompressNetInfo);
			EventAPI.OnAssetsLoaded += NetworkCompression.Initialize;
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.0.0+git50a4b1a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "NetworkCompression";

		public const string Version = "1.0.0";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = null;

		public const string SemVer = "1.0.0";

		public const string GitRevShort = null;

		public const string GitRevLong = null;

		public const string GitBranch = null;

		public const string GitTag = null;

		public const bool GitIsDirty = false;
	}
}