Decompiled source of ConnectFix v1.0.0

plugins/ElfDevelop.ConnectFix.dll

Decompiled 15 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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]
	[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]
	[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 ConnectFix
{
	[ContentWarningPlugin("ElfDevelop.ConnectFix", "1.0.0", true)]
	[BepInPlugin("ElfDevelop.ConnectFix", "ConnectFix", "1.0.0")]
	public class ConnectFixPlugin : BaseUnityPlugin
	{
		internal const int FirstRoomViewId = 500;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("ElfDevelop.ConnectFix").PatchAll();
			Logger.LogInfo((object)$"ConnectFix 1.0.0 has loaded! Room objects get view IDs from {500}");
		}
	}
	[HarmonyPatch(typeof(PhotonNetwork), "AllocateViewID", new Type[] { typeof(int) })]
	internal static class AllocateRoomViewIdPatch
	{
		private static readonly FieldInfo LastUsed = AccessTools.Field(typeof(PhotonNetwork), "lastUsedViewSubIdStatic");

		[HarmonyPrefix]
		private static bool Prefix(int ownerId, ref int __result)
		{
			if (ownerId != 0)
			{
				return true;
			}
			int mAX_VIEW_IDS = PhotonNetwork.MAX_VIEW_IDS;
			int val = (int)LastUsed.GetValue(null);
			int num = mAX_VIEW_IDS - 500;
			for (int i = 1; i <= num; i++)
			{
				int num2 = 500 + (Math.Max(val, 499) - 500 + i) % num;
				if ((Object)(object)PhotonNetwork.GetPhotonView(num2) == (Object)null)
				{
					LastUsed.SetValue(null, num2);
					__result = num2;
					return false;
				}
			}
			ConnectFixPlugin.Logger.LogWarning((object)$"No free room view ID from {500}, using the default allocation");
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}