Decompiled source of Network v1.0.1

Network.dll

Decompiled 2 years ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Network")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/Smoothbrain/Network")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Network")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9BC6D744-34E6-432C-929F-371CF06CEFBD")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[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 Network
{
	[BepInPlugin("org.bepinex.plugins.network", "Network", "1.0.1")]
	public class Network : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ZSteamSocket), "RegisterGlobalCallbacks")]
		private static class IncreaseSendingLimit
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				foreach (CodeInstruction instruction in instructions)
				{
					if (instruction.opcode == OpCodes.Ldc_I4 && CodeInstructionExtensions.OperandIs(instruction, (object)153600))
					{
						instruction.operand = 50000000;
					}
					yield return instruction;
				}
			}

			private static void Postfix()
			{
				if (CSteamAPIContext.GetSteamClient() != IntPtr.Zero)
				{
					GCHandle gCHandle = GCHandle.Alloc(100000000, GCHandleType.Pinned);
					SteamNetworkingUtils.SetConfigValue((ESteamNetworkingConfigValue)9, (ESteamNetworkingConfigScope)1, IntPtr.Zero, (ESteamNetworkingConfigDataType)1, gCHandle.AddrOfPinnedObject());
					gCHandle.Free();
				}
			}
		}

		private const string ModName = "Network";

		private const string ModVersion = "1.0.1";

		private const string ModGUID = "org.bepinex.plugins.network";

		public void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			new Harmony("org.bepinex.plugins.network").PatchAll(executingAssembly);
		}
	}
	public static class ZDODataBuffer
	{
		[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
		private class StartBufferingOnNewConnection
		{
			private static void Postfix(ZNet __instance, ZNetPeer peer)
			{
				if (!__instance.IsServer())
				{
					peer.m_rpc.Register<ZPackage>("ZDOData", (Action<ZRpc, ZPackage>)delegate(ZRpc _, ZPackage package)
					{
						packageBuffer.Add(package);
					});
				}
			}
		}

		[HarmonyPatch(typeof(ZNet), "Shutdown")]
		private class ClearPackageBufferOnShutdown
		{
			private static void Postfix()
			{
				packageBuffer.Clear();
			}
		}

		[HarmonyPatch(typeof(ZDOMan), "AddPeer")]
		private class EvaluateBufferedPackages
		{
			private static void Postfix(ZDOMan __instance, ZNetPeer netPeer)
			{
				foreach (ZPackage item in packageBuffer)
				{
					__instance.RPC_ZDOData(netPeer.m_rpc, item);
				}
				packageBuffer.Clear();
			}
		}

		private static readonly List<ZPackage> packageBuffer = new List<ZPackage>();
	}
}