Decompiled source of CustomJoinVerifierFix v1.0.0

plugins/CustomJoinVerifierFix/CustomJoinVerifierFix.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using FrooxEngine;
using FrooxEngine.ProtoFlux.Runtimes.Execution.Nodes.FrooxEngine.Security;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v10.0", FrameworkDisplayName = ".NET 10.0")]
[assembly: AssemblyCompany("art0007i")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d92cc24902214eba4945189ed5ecff2049702fa2")]
[assembly: AssemblyProduct("CustomJoinVerifierFix")]
[assembly: AssemblyTitle("CustomJoinVerifierFix")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/art0007i/CustomJoinVerifierFix")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace CustomJoinVerifierFix;

[ResonitePlugin("art0007i.CustomJoinVerifierFix", "CustomJoinVerifierFix", "1.0.0", "art0007i", "https://github.com/art0007i/CustomJoinVerifierFix")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch(typeof(SessionControlDialog), "OnCommonUpdate")]
	private class CustomJoinVerifierFixPatch
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__1 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, global::System.Collections.IEnumerator, global::System.IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private global::System.Collections.Generic.IEnumerable<CodeInstruction> codes;

			public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__codes;

			private FieldInfo <worldVerif>5__2;

			private MethodInfo <isAuthor>5__3;

			private MethodInfo <proxFunc>5__4;

			private bool <foundMatch>5__5;

			private global::System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap5;

			CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object global::System.Collections.IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void global::System.IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<worldVerif>5__2 = null;
				<isAuthor>5__3 = null;
				<proxFunc>5__4 = null;
				<>7__wrap5 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00df: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<worldVerif>5__2 = typeof(WorldConfiguration).GetField("CustomJoinVerifier");
						<isAuthor>5__3 = typeof(World).GetProperty("IsAuthority").GetMethod;
						<proxFunc>5__4 = typeof(CustomJoinVerifierFixPatch).GetMethod("PermCheck");
						<foundMatch>5__5 = false;
						<>7__wrap5 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (((global::System.Collections.IEnumerator)<>7__wrap5).MoveNext())
					{
						CodeInstruction current = <>7__wrap5.Current;
						if (CodeInstructionExtensions.LoadsField(current, <worldVerif>5__2, false))
						{
							<foundMatch>5__5 = true;
						}
						if (<foundMatch>5__5 && CodeInstructionExtensions.Calls(current, <isAuthor>5__3))
						{
							<foundMatch>5__5 = false;
							<>2__current = new CodeInstruction(OpCodes.Call, (object)<proxFunc>5__4);
							<>1__state = 1;
							return true;
						}
						<>2__current = current;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap5 = null;
					return false;
				}
				catch
				{
					//try-fault
					((global::System.IDisposable)this).Dispose();
					throw;
				}
			}

			bool global::System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap5 != null)
				{
					((global::System.IDisposable)<>7__wrap5).Dispose();
				}
			}

			[DebuggerHidden]
			void global::System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			global::System.Collections.Generic.IEnumerator<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__1 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__1(0);
				}
				<Transpiler>d__.codes = <>3__codes;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
			{
				return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		public static bool PermCheck(World wld)
		{
			return WorldConfigurationPermissionsExtensions.CanChangeProperties(wld.Configuration);
		}

		[IteratorStateMachine(typeof(<Transpiler>d__1))]
		public static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			FieldInfo worldVerif = typeof(WorldConfiguration).GetField("CustomJoinVerifier");
			MethodInfo isAuthor = typeof(World).GetProperty("IsAuthority").GetMethod;
			MethodInfo proxFunc = typeof(CustomJoinVerifierFixPatch).GetMethod("PermCheck");
			bool foundMatch = false;
			global::System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CodeInstruction current = enumerator.Current;
					if (CodeInstructionExtensions.LoadsField(current, worldVerif, false))
					{
						foundMatch = true;
					}
					if (foundMatch && CodeInstructionExtensions.Calls(current, isAuthor))
					{
						foundMatch = false;
						yield return new CodeInstruction(OpCodes.Call, (object)proxFunc);
					}
					else
					{
						yield return current;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}
	}

	[HarmonyPatch(typeof(VerifyJoinRequest), "OnSetAsCustomJoinRequestVerifier")]
	private class SetCustomJoinVerifierFixPatch
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__1 : global::System.Collections.Generic.IEnumerable<CodeInstruction>, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator<CodeInstruction>, global::System.Collections.IEnumerator, global::System.IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

			private global::System.Collections.Generic.IEnumerable<CodeInstruction> codes;

			public global::System.Collections.Generic.IEnumerable<CodeInstruction> <>3__codes;

			private MethodInfo <isHost>5__2;

			private MethodInfo <proxFunc>5__3;

			private global::System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap3;

			CodeInstruction global::System.Collections.Generic.IEnumerator<CodeInstruction>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object global::System.Collections.IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <Transpiler>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
				<>l__initialThreadId = Environment.CurrentManagedThreadId;
			}

			[DebuggerHidden]
			void global::System.IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 1u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<isHost>5__2 = null;
				<proxFunc>5__3 = null;
				<>7__wrap3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ab: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<isHost>5__2 = typeof(User).GetProperty("IsHost").GetMethod;
						<proxFunc>5__3 = typeof(SetCustomJoinVerifierFixPatch).GetMethod("PermCheck");
						<>7__wrap3 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (((global::System.Collections.IEnumerator)<>7__wrap3).MoveNext())
					{
						CodeInstruction current = <>7__wrap3.Current;
						if (CodeInstructionExtensions.Calls(current, <isHost>5__2))
						{
							<>2__current = new CodeInstruction(OpCodes.Call, (object)<proxFunc>5__3);
							<>1__state = 1;
							return true;
						}
						<>2__current = current;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap3 = null;
					return false;
				}
				catch
				{
					//try-fault
					((global::System.IDisposable)this).Dispose();
					throw;
				}
			}

			bool global::System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<>7__wrap3 != null)
				{
					((global::System.IDisposable)<>7__wrap3).Dispose();
				}
			}

			[DebuggerHidden]
			void global::System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}

			[DebuggerHidden]
			global::System.Collections.Generic.IEnumerator<CodeInstruction> global::System.Collections.Generic.IEnumerable<CodeInstruction>.GetEnumerator()
			{
				<Transpiler>d__1 <Transpiler>d__;
				if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId)
				{
					<>1__state = 0;
					<Transpiler>d__ = this;
				}
				else
				{
					<Transpiler>d__ = new <Transpiler>d__1(0);
				}
				<Transpiler>d__.codes = <>3__codes;
				return <Transpiler>d__;
			}

			[DebuggerHidden]
			global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
			{
				return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		public static bool PermCheck(User user)
		{
			return CustomJoinVerifierFixPatch.PermCheck(((Worker)user).World);
		}

		[IteratorStateMachine(typeof(<Transpiler>d__1))]
		public static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			MethodInfo isHost = typeof(User).GetProperty("IsHost").GetMethod;
			MethodInfo proxFunc = typeof(SetCustomJoinVerifierFixPatch).GetMethod("PermCheck");
			global::System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
			try
			{
				while (((global::System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CodeInstruction current = enumerator.Current;
					if (CodeInstructionExtensions.Calls(current, isHost))
					{
						yield return new CodeInstruction(OpCodes.Call, (object)proxFunc);
					}
					else
					{
						yield return current;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}
	}

	internal static ManualLogSource Log;

	public override void Load()
	{
		Log = ((BasePlugin)this).Log;
		((BasePlugin)this).HarmonyInstance.PatchAll();
	}
}
public static class PluginMetadata
{
	public const string GUID = "art0007i.CustomJoinVerifierFix";

	public const string NAME = "CustomJoinVerifierFix";

	public const string VERSION = "1.0.0";

	public const string AUTHORS = "art0007i";

	public const string REPOSITORY_URL = "https://github.com/art0007i/CustomJoinVerifierFix";
}