Decompiled source of PEAKERRpcInfo v1.0.0

BepInEx/patchers/PEAKERRpcInfo.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
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.Logging;
using Microsoft.CodeAnalysis;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Cecil.Rocks;
using Mono.Collections.Generic;
using MonoMod.Cil;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PEAKERRpcInfo")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PEAKERRpcInfo")]
[assembly: AssemblyTitle("PEAKERRpcInfo")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PEAKERRpcInfo
{
	public static class PEAKERRpcInfo
	{
		public static IEnumerable<string> TargetDLLs { get; } = new <>z__ReadOnlySingleElementList<string>("Assembly-CSharp.dll");


		public static void Patch(AssemblyDefinition assembly)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Expected O, but got Unknown
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource val = Logger.CreateLogSource("PEAKERRpcInfo");
			TypeReference val2 = default(TypeReference);
			if (!assembly.MainModule.TryGetTypeReference("Photon.Pun.PhotonMessageInfo", ref val2))
			{
				val.LogFatal((object)"Photon.Pun.PhotonMessageInfo type not found.");
				return;
			}
			List<MethodDefinition> list = new List<MethodDefinition>();
			foreach (TypeDefinition type in assembly.MainModule.GetTypes())
			{
				Enumerator<MethodDefinition> enumerator2 = type.Methods.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						MethodDefinition current = enumerator2.Current;
						try
						{
							if (current.HasBody && current.HasCustomAttributes && ((IEnumerable<CustomAttribute>)current.CustomAttributes).Any((CustomAttribute attribute) => ((object)attribute.AttributeType).ToString() == "Photon.Pun.PunRPC") && !((IEnumerable<ParameterDefinition>)((MethodReference)current).Parameters).Any((ParameterDefinition parameter) => ((object)((ParameterReference)parameter).ParameterType).ToString() == "Photon.Pun.PhotonMessageInfo"))
							{
								((MethodReference)current).Parameters.Add(new ParameterDefinition("info", (ParameterAttributes)16, val2));
								val.LogDebug((object)("Added Photon.Pun.PhotonMessageInfo info parameter onto " + ((MemberReference)current).FullName));
								list.Add(current);
							}
						}
						catch (Exception arg)
						{
							val.LogError((object)$"An exception occured adding to the parameters of {((MemberReference)current).FullName}:\n{arg}");
						}
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
			}
			foreach (TypeDefinition type2 in assembly.MainModule.GetTypes())
			{
				Enumerator<MethodDefinition> enumerator2 = type2.Methods.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						MethodDefinition current2 = enumerator2.Current;
						if (((current2 != null) ? current2.Body : null) == null)
						{
							continue;
						}
						List<Instruction> list2 = new List<Instruction>();
						try
						{
							Enumerator<Instruction> enumerator3 = current2.Body.Instructions.GetEnumerator();
							try
							{
								while (enumerator3.MoveNext())
								{
									Instruction current3 = enumerator3.Current;
									foreach (MethodDefinition item in list)
									{
										if (ILPatternMatchingExt.MatchCallOrCallvirt(current3, (MethodReference)(object)item))
										{
											list2.Add(current3);
											break;
										}
									}
								}
							}
							finally
							{
								((IDisposable)enumerator3).Dispose();
							}
							if (list2.Count == 0)
							{
								continue;
							}
							VariableDefinition val3 = new VariableDefinition(val2);
							current2.Body.Variables.Add(val3);
							val.LogDebug((object)("Added Photon.Pun.PhotonMessageInfo variable to " + ((MemberReference)current2).FullName));
							MethodBodyRocks.SimplifyMacros(current2.Body);
							ILProcessor iLProcessor = current2.Body.GetILProcessor();
							foreach (Instruction item2 in list2)
							{
								iLProcessor.InsertBefore(item2, iLProcessor.Create(OpCodes.Ldloca_S, val3));
								iLProcessor.InsertBefore(item2, iLProcessor.Create(OpCodes.Initobj, val2));
								iLProcessor.InsertBefore(item2, iLProcessor.Create(OpCodes.Ldloc_S, val3));
								val.LogDebug((object)("Inserted default(Photon.Pun.PhotonMessageInfo) before call to " + ((MemberReference)(MethodDefinition)item2.Operand).FullName));
							}
						}
						catch (Exception arg2)
						{
							val.LogError((object)$"An exception occured inserting default(Photon.Pun.PhotonMessageInfo) into {((MemberReference)current2).FullName}:\n{arg2}");
						}
						finally
						{
							if (list2.Count != 0)
							{
								MethodBodyRocks.OptimizeMacros(current2.Body);
							}
						}
					}
				}
				finally
				{
					((IDisposable)enumerator2).Dispose();
				}
			}
		}
	}
}
[CompilerGenerated]
internal sealed class <>z__ReadOnlySingleElementList<T> : IEnumerable, ICollection, IList, IEnumerable<T>, IReadOnlyCollection<T>, IReadOnlyList<T>, ICollection<T>, IList<T>
{
	private sealed class Enumerator : IDisposable, IEnumerator, IEnumerator<T>
	{
		object IEnumerator.Current => _item;

		T IEnumerator<T>.Current => _item;

		public Enumerator(T item)
		{
			_item = item;
		}

		bool IEnumerator.MoveNext()
		{
			if (!_moveNextCalled)
			{
				return _moveNextCalled = true;
			}
			return false;
		}

		void IEnumerator.Reset()
		{
			_moveNextCalled = false;
		}

		void IDisposable.Dispose()
		{
		}
	}

	int ICollection.Count => 1;

	bool ICollection.IsSynchronized => false;

	object ICollection.SyncRoot => this;

	object IList.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	bool IList.IsFixedSize => true;

	bool IList.IsReadOnly => true;

	int IReadOnlyCollection<T>.Count => 1;

	T IReadOnlyList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
	}

	int ICollection<T>.Count => 1;

	bool ICollection<T>.IsReadOnly => true;

	T IList<T>.this[int index]
	{
		get
		{
			if (index != 0)
			{
				throw new IndexOutOfRangeException();
			}
			return _item;
		}
		set
		{
			throw new NotSupportedException();
		}
	}

	public <>z__ReadOnlySingleElementList(T item)
	{
		_item = item;
	}

	IEnumerator IEnumerable.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection.CopyTo(Array array, int index)
	{
		array.SetValue(_item, index);
	}

	int IList.Add(object value)
	{
		throw new NotSupportedException();
	}

	void IList.Clear()
	{
		throw new NotSupportedException();
	}

	bool IList.Contains(object value)
	{
		return EqualityComparer<T>.Default.Equals(_item, (T)value);
	}

	int IList.IndexOf(object value)
	{
		if (!EqualityComparer<T>.Default.Equals(_item, (T)value))
		{
			return -1;
		}
		return 0;
	}

	void IList.Insert(int index, object value)
	{
		throw new NotSupportedException();
	}

	void IList.Remove(object value)
	{
		throw new NotSupportedException();
	}

	void IList.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}

	IEnumerator<T> IEnumerable<T>.GetEnumerator()
	{
		return new Enumerator(_item);
	}

	void ICollection<T>.Add(T item)
	{
		throw new NotSupportedException();
	}

	void ICollection<T>.Clear()
	{
		throw new NotSupportedException();
	}

	bool ICollection<T>.Contains(T item)
	{
		return EqualityComparer<T>.Default.Equals(_item, item);
	}

	void ICollection<T>.CopyTo(T[] array, int arrayIndex)
	{
		array[arrayIndex] = _item;
	}

	bool ICollection<T>.Remove(T item)
	{
		throw new NotSupportedException();
	}

	int IList<T>.IndexOf(T item)
	{
		if (!EqualityComparer<T>.Default.Equals(_item, item))
		{
			return -1;
		}
		return 0;
	}

	void IList<T>.Insert(int index, T item)
	{
		throw new NotSupportedException();
	}

	void IList<T>.RemoveAt(int index)
	{
		throw new NotSupportedException();
	}
}