Decompiled source of BepInExResoniteShim v0.10.0

plugins/BepInExResoniteShim/BepInExResoniteShim.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using Elements.Core;
using FrooxEngine;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v11.0", FrameworkDisplayName = ".NET 11.0")]
[assembly: IgnoresAccessChecksTo("Renderite.Host")]
[assembly: AssemblyCompany("ResoniteModding")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright (c) ResoniteModding 2026")]
[assembly: AssemblyDescription("Patches which allow Resonite to run with BepisLoader.")]
[assembly: AssemblyFileVersion("0.10.0.0")]
[assembly: AssemblyInformationalVersion("0.10.0+85f501140b216e730ae2e4f1ec4820f18fd35f8f")]
[assembly: AssemblyProduct("BepInEx Resonite Shim")]
[assembly: AssemblyTitle("BepInExResoniteShim")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ResoniteModding/BepInExResoniteShim")]
[assembly: SecurityPermission((SecurityAction)8, SkipVerification = true)]
[assembly: AssemblyVersion("0.10.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace BepInExResoniteShim
{
	[HarmonyPatch(typeof(EngineInitializer), "InitializeFrooxEngine")]
	internal class AssemblyLoadFixer
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : System.Collections.Generic.IEnumerable<CodeInstruction>, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator<CodeInstruction>, System.Collections.IEnumerator, System.IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

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

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

			private MethodInfo <loadFrom>5__2;

			private System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_008b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<loadFrom>5__2 = AccessTools.Method(typeof(Assembly), "LoadFrom", new System.Type[1] { typeof(string) }, (System.Type[])null);
						<>7__wrap2 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (((System.Collections.IEnumerator)<>7__wrap2).MoveNext())
					{
						CodeInstruction current = <>7__wrap2.Current;
						if (CodeInstructionExtensions.Calls(current, <loadFrom>5__2))
						{
							<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AssemblyLoadFixer), "LoadFrom", (System.Type[])null, (System.Type[])null));
							<>1__state = 1;
							return true;
						}
						<>2__current = current;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap2 = null;
					return false;
				}
				catch
				{
					//try-fault
					((System.IDisposable)this).Dispose();
					throw;
				}
			}

			bool 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__wrap2 != null)
				{
					((System.IDisposable)<>7__wrap2).Dispose();
				}
			}

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

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

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

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		public static System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			MethodInfo loadFrom = AccessTools.Method(typeof(Assembly), "LoadFrom", new System.Type[1] { typeof(string) }, (System.Type[])null);
			System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CodeInstruction current = enumerator.Current;
					if (CodeInstructionExtensions.Calls(current, loadFrom))
					{
						yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(AssemblyLoadFixer), "LoadFrom", (System.Type[])null, (System.Type[])null));
					}
					else
					{
						yield return current;
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
		}

		public static Assembly? LoadFrom(string path)
		{
			BepInExResoniteShim.Log.LogDebug((object)("Bypassing LoadFrom: " + path));
			return null;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class GraphicalClientPatch
	{
		public static void Postfix(ref string ___AssemblyDirectory)
		{
			___AssemblyDirectory = Paths.GameRootPath;
		}
	}
	[HarmonyPatch]
	internal class LocationFixer
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__1 : System.Collections.Generic.IEnumerable<CodeInstruction>, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator<CodeInstruction>, System.Collections.IEnumerator, System.IDisposable
		{
			private int <>1__state;

			private CodeInstruction <>2__current;

			private int <>l__initialThreadId;

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

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

			private int <killCount>5__2;

			private MethodInfo <cachePath>5__3;

			private MethodInfo <asmLoc>5__4;

			private System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap4;

			private CodeInstruction <code>5__6;

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

			object 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 System.IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || (uint)(num - 1) <= 3u)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<cachePath>5__3 = null;
				<asmLoc>5__4 = null;
				<>7__wrap4 = null;
				<code>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0187: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Expected O, but got Unknown
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_0169: Unknown result type (might be due to invalid IL or missing references)
				//IL_0173: Expected O, but got Unknown
				//IL_00da: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<killCount>5__2 = 0;
						<cachePath>5__3 = AccessTools.PropertyGetter(typeof(GlobalTypeRegistry), "MetadataCachePath");
						<asmLoc>5__4 = AccessTools.PropertyGetter(typeof(Assembly), "Location");
						<>7__wrap4 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						<killCount>5__2 = 2;
						goto IL_0140;
					case 2:
						<>1__state = -3;
						goto IL_0140;
					case 3:
						<>1__state = -3;
						<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LocationFixer), "ProcessCachePath", (System.Type[])null, (System.Type[])null));
						<>1__state = 4;
						return true;
					case 4:
						{
							<>1__state = -3;
							goto IL_01bf;
						}
						IL_0140:
						if (CodeInstructionExtensions.Calls(<code>5__6, <cachePath>5__3))
						{
							BepInExResoniteShim.Log.LogDebug((object)"Patched CachePath");
							<>2__current = new CodeInstruction(OpCodes.Ldarg_1, (object)null);
							<>1__state = 3;
							return true;
						}
						goto IL_01bf;
						IL_01bf:
						<code>5__6 = null;
						break;
					}
					while (((System.Collections.IEnumerator)<>7__wrap4).MoveNext())
					{
						<code>5__6 = <>7__wrap4.Current;
						if (<killCount>5__2 > 0)
						{
							<killCount>5__2--;
							continue;
						}
						if (CodeInstructionExtensions.Calls(<code>5__6, <asmLoc>5__4))
						{
							BepInExResoniteShim.Log.LogDebug((object)"Patched AsmLoc");
							<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LocationFixer), "ProcessCacheTime", (System.Type[])null, (System.Type[])null));
							<>1__state = 1;
							return true;
						}
						<>2__current = <code>5__6;
						<>1__state = 2;
						return true;
					}
					<>m__Finally1();
					<>7__wrap4 = null;
					return false;
				}
				catch
				{
					//try-fault
					((System.IDisposable)this).Dispose();
					throw;
				}
			}

			bool 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__wrap4 != null)
				{
					((System.IDisposable)<>7__wrap4).Dispose();
				}
			}

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

			[DebuggerHidden]
			System.Collections.Generic.IEnumerator<CodeInstruction> 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]
			System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
			{
				return (System.Collections.IEnumerator)((System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		public static MethodBase TargetMethod()
		{
			return (MethodBase)(object)AccessTools.FirstConstructor(typeof(AssemblyTypeRegistry), (Func<ConstructorInfo, bool>)((ConstructorInfo x) => ((MethodBase)x).GetParameters().Length > 3));
		}

		[IteratorStateMachine(typeof(<Transpiler>d__1))]
		public static System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			int killCount = 0;
			MethodInfo cachePath = AccessTools.PropertyGetter(typeof(GlobalTypeRegistry), "MetadataCachePath");
			MethodInfo asmLoc = AccessTools.PropertyGetter(typeof(Assembly), "Location");
			System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					CodeInstruction code = enumerator.Current;
					if (killCount > 0)
					{
						killCount--;
						continue;
					}
					if (CodeInstructionExtensions.Calls(code, asmLoc))
					{
						BepInExResoniteShim.Log.LogDebug((object)"Patched AsmLoc");
						yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LocationFixer), "ProcessCacheTime", (System.Type[])null, (System.Type[])null));
						killCount = 2;
					}
					else
					{
						yield return code;
					}
					if (CodeInstructionExtensions.Calls(code, cachePath))
					{
						BepInExResoniteShim.Log.LogDebug((object)"Patched CachePath");
						yield return new CodeInstruction(OpCodes.Ldarg_1, (object)null);
						yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(LocationFixer), "ProcessCachePath", (System.Type[])null, (System.Type[])null));
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
		}

		public static string? ProcessCachePath(string cachePath, Assembly asm)
		{
			if (string.IsNullOrWhiteSpace(asm.Location))
			{
				return null;
			}
			return cachePath;
		}

		public static System.DateTime ProcessCacheTime(Assembly asm)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(asm.Location))
			{
				return System.DateTime.UtcNow;
			}
			return ((FileSystemInfo)new FileInfo(asm.Location)).LastWriteTimeUtc;
		}
	}
	[HarmonyPatch(typeof(UniLog), "add_OnLog")]
	internal class LogAlerter
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass1_0
		{
			[StructLayout((LayoutKind)3)]
			private struct <<Postfix>b__0>d : IAsyncStateMachine
			{
				public int <>1__state;

				public AsyncTaskMethodBuilder <>t__builder;

				public <>c__DisplayClass1_0 <>4__this;

				private System.DateTime <timeout>5__2;

				private TaskAwaiter <>u__1;

				private void MoveNext()
				{
					//IL_0078: Unknown result type (might be due to invalid IL or missing references)
					//IL_007d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0084: Unknown result type (might be due to invalid IL or missing references)
					//IL_0045: Unknown result type (might be due to invalid IL or missing references)
					//IL_004a: Unknown result type (might be due to invalid IL or missing references)
					//IL_005e: Unknown result type (might be due to invalid IL or missing references)
					//IL_005f: Unknown result type (might be due to invalid IL or missing references)
					int num = <>1__state;
					<>c__DisplayClass1_0 <>c__DisplayClass1_ = <>4__this;
					try
					{
						if (num != 0)
						{
							if (_logStreamField != (FieldInfo)null)
							{
								<timeout>5__2 = System.DateTime.UtcNow.AddSeconds(10.0);
								goto IL_009a;
							}
							goto IL_00b9;
						}
						TaskAwaiter val = <>u__1;
						<>u__1 = default(TaskAwaiter);
						num = (<>1__state = -1);
						goto IL_0093;
						IL_0093:
						((TaskAwaiter)(ref val)).GetResult();
						goto IL_009a;
						IL_009a:
						if (_logStreamField.GetValue((object)null) == null && System.DateTime.UtcNow < <timeout>5__2)
						{
							val = System.Threading.Tasks.Task.Delay(1).GetAwaiter();
							if (!((TaskAwaiter)(ref val)).IsCompleted)
							{
								num = (<>1__state = 0);
								<>u__1 = val;
								((AsyncTaskMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter, <<Postfix>b__0>d>(ref val, ref this);
								return;
							}
							goto IL_0093;
						}
						goto IL_00b9;
						IL_00b9:
						if (BepInExResoniteShim.AnyPatchFailed)
						{
							<>c__DisplayClass1_.value.Invoke("[BepisLoader] BepInExResoniteShim partially loaded.");
						}
						else
						{
							<>c__DisplayClass1_.value.Invoke("[BepisLoader] BepInExResoniteShim loaded successfully.");
						}
					}
					catch (System.Exception exception)
					{
						<>1__state = -2;
						((AsyncTaskMethodBuilder)(ref <>t__builder)).SetException(exception);
						return;
					}
					<>1__state = -2;
					((AsyncTaskMethodBuilder)(ref <>t__builder)).SetResult();
				}

				[DebuggerHidden]
				private void SetStateMachine(IAsyncStateMachine stateMachine)
				{
					((AsyncTaskMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
				}
			}

			public Action<string> value;

			[AsyncStateMachine(typeof(<<Postfix>b__0>d))]
			internal System.Threading.Tasks.Task? <Postfix>b__0()
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				<<Postfix>b__0>d <<Postfix>b__0>d = default(<<Postfix>b__0>d);
				<<Postfix>b__0>d.<>t__builder = AsyncTaskMethodBuilder.Create();
				<<Postfix>b__0>d.<>4__this = this;
				<<Postfix>b__0>d.<>1__state = -1;
				((AsyncTaskMethodBuilder)(ref <<Postfix>b__0>d.<>t__builder)).Start<<<Postfix>b__0>d>(ref <<Postfix>b__0>d);
				return ((AsyncTaskMethodBuilder)(ref <<Postfix>b__0>d.<>t__builder)).Task;
			}
		}

		private static readonly FieldInfo? _logStreamField = AccessTools.Field(System.Type.GetType("FrooxEngine.Headless.Program, Resonite"), "logStream");

		private static void Postfix(Action<string> value)
		{
			<>c__DisplayClass1_0 <>c__DisplayClass1_ = new <>c__DisplayClass1_0();
			<>c__DisplayClass1_.value = value;
			System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task>)([AsyncStateMachine(typeof(<>c__DisplayClass1_0.<<Postfix>b__0>d))] () =>
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				<>c__DisplayClass1_0.<<Postfix>b__0>d <<Postfix>b__0>d = default(<>c__DisplayClass1_0.<<Postfix>b__0>d);
				<<Postfix>b__0>d.<>t__builder = AsyncTaskMethodBuilder.Create();
				<<Postfix>b__0>d.<>4__this = <>c__DisplayClass1_;
				<<Postfix>b__0>d.<>1__state = -1;
				((AsyncTaskMethodBuilder)(ref <<Postfix>b__0>d.<>t__builder)).Start<<>c__DisplayClass1_0.<<Postfix>b__0>d>(ref <<Postfix>b__0>d);
				return ((AsyncTaskMethodBuilder)(ref <<Postfix>b__0>d.<>t__builder)).Task;
			}));
		}
	}
	internal class RelativePathFixer
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private class RenderiteHostPathFixes
		{
			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : System.Collections.Generic.IEnumerable<CodeInstruction>, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator<CodeInstruction>, System.Collections.IEnumerator, System.IDisposable
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

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

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

				private System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap1;

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

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

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

				[DebuggerHidden]
				void System.IDisposable.Dispose()
				{
					int num = <>1__state;
					if (num == -3 || (uint)(num - 1) <= 3u)
					{
						try
						{
						}
						finally
						{
							<>m__Finally1();
						}
					}
					<>7__wrap1 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_005a: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
					//IL_006c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0080: Unknown result type (might be due to invalid IL or missing references)
					//IL_008a: Expected O, but got Unknown
					//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
					//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d6: Expected O, but got Unknown
					//IL_0110: Unknown result type (might be due to invalid IL or missing references)
					//IL_012b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0135: Expected O, but got Unknown
					try
					{
						switch (<>1__state)
						{
						default:
							return false;
						case 0:
							<>1__state = -1;
							<>7__wrap1 = codes.GetEnumerator();
							<>1__state = -3;
							break;
						case 1:
							<>1__state = -3;
							break;
						case 2:
							<>1__state = -3;
							break;
						case 3:
							<>1__state = -3;
							break;
						case 4:
							<>1__state = -3;
							break;
						}
						if (((System.Collections.IEnumerator)<>7__wrap1).MoveNext())
						{
							CodeInstruction current = <>7__wrap1.Current;
							if (CodeInstructionExtensions.Is(current, OpCodes.Ldstr, (object)"Logs"))
							{
								<>2__current = new CodeInstruction(OpCodes.Ldstr, (object)Path.Combine(Paths.GameRootPath, "Logs"));
								<>1__state = 1;
								return true;
							}
							if (CodeInstructionExtensions.Is(current, OpCodes.Ldstr, (object)"Icon.png"))
							{
								<>2__current = new CodeInstruction(OpCodes.Ldstr, (object)Path.Combine(Paths.GameRootPath, "Icon.png"));
								<>1__state = 2;
								return true;
							}
							object operand = current.operand;
							MethodInfo val = (MethodInfo)((operand is MethodInfo) ? operand : null);
							if (val != null && ((MemberInfo)val).Name == "WriteAllText")
							{
								<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RenderiteHostPathFixes), "FileWriteInjected", (System.Type[])null, (System.Type[])null));
								<>1__state = 3;
								return true;
							}
							<>2__current = current;
							<>1__state = 4;
							return true;
						}
						<>m__Finally1();
						<>7__wrap1 = null;
						return false;
					}
					catch
					{
						//try-fault
						((System.IDisposable)this).Dispose();
						throw;
					}
				}

				bool 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__wrap1 != null)
					{
						((System.IDisposable)<>7__wrap1).Dispose();
					}
				}

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

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

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

			[IteratorStateMachine(typeof(<Transpiler>d__0))]
			public static System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(System.Collections.Generic.IEnumerable<CodeInstruction> codes)
			{
				System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						CodeInstruction current = enumerator.Current;
						if (CodeInstructionExtensions.Is(current, OpCodes.Ldstr, (object)"Logs"))
						{
							yield return new CodeInstruction(OpCodes.Ldstr, (object)Path.Combine(Paths.GameRootPath, "Logs"));
							continue;
						}
						if (CodeInstructionExtensions.Is(current, OpCodes.Ldstr, (object)"Icon.png"))
						{
							yield return new CodeInstruction(OpCodes.Ldstr, (object)Path.Combine(Paths.GameRootPath, "Icon.png"));
							continue;
						}
						object operand = current.operand;
						MethodInfo val = (MethodInfo)((operand is MethodInfo) ? operand : null);
						if (val != null && ((MemberInfo)val).Name == "WriteAllText")
						{
							yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(RenderiteHostPathFixes), "FileWriteInjected", (System.Type[])null, (System.Type[])null));
						}
						else
						{
							yield return current;
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
			}

			public static void FileWriteInjected(string path, string? contents)
			{
				if (!Path.IsPathRooted(path))
				{
					path = Path.Combine(Paths.GameRootPath, path);
				}
				File.WriteAllText(path, contents);
			}
		}

		[HarmonyPatch(typeof(RenderSystem), "StartRenderer")]
		public class RenderiteWorkingDirectoryFix
		{
			[CompilerGenerated]
			private sealed class <Transpiler>d__0 : System.Collections.Generic.IEnumerable<CodeInstruction>, System.Collections.IEnumerable, System.Collections.Generic.IEnumerator<CodeInstruction>, System.Collections.IEnumerator, System.IDisposable
			{
				private int <>1__state;

				private CodeInstruction <>2__current;

				private int <>l__initialThreadId;

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

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

				private System.Collections.Generic.IEnumerator<CodeInstruction> <>7__wrap1;

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

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

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

				[DebuggerHidden]
				void System.IDisposable.Dispose()
				{
					int num = <>1__state;
					if (num == -3 || (uint)(num - 1) <= 1u)
					{
						try
						{
						}
						finally
						{
							<>m__Finally1();
						}
					}
					<>7__wrap1 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_004f: Unknown result type (might be due to invalid IL or missing references)
					//IL_0061: Unknown result type (might be due to invalid IL or missing references)
					//IL_0075: Unknown result type (might be due to invalid IL or missing references)
					//IL_007f: Expected O, but got Unknown
					try
					{
						switch (<>1__state)
						{
						default:
							return false;
						case 0:
							<>1__state = -1;
							<>7__wrap1 = codes.GetEnumerator();
							<>1__state = -3;
							break;
						case 1:
							<>1__state = -3;
							break;
						case 2:
							<>1__state = -3;
							break;
						}
						if (((System.Collections.IEnumerator)<>7__wrap1).MoveNext())
						{
							CodeInstruction current = <>7__wrap1.Current;
							if (CodeInstructionExtensions.Is(current, OpCodes.Ldstr, (object)"Renderer"))
							{
								<>2__current = new CodeInstruction(OpCodes.Ldstr, (object)Path.Combine(Paths.GameRootPath, "Renderer"));
								<>1__state = 1;
								return true;
							}
							<>2__current = current;
							<>1__state = 2;
							return true;
						}
						<>m__Finally1();
						<>7__wrap1 = null;
						return false;
					}
					catch
					{
						//try-fault
						((System.IDisposable)this).Dispose();
						throw;
					}
				}

				bool 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__wrap1 != null)
					{
						((System.IDisposable)<>7__wrap1).Dispose();
					}
				}

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

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

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

			[IteratorStateMachine(typeof(<Transpiler>d__0))]
			public static System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(System.Collections.Generic.IEnumerable<CodeInstruction> codes)
			{
				System.Collections.Generic.IEnumerator<CodeInstruction> enumerator = codes.GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						CodeInstruction current = enumerator.Current;
						if (CodeInstructionExtensions.Is(current, OpCodes.Ldstr, (object)"Renderer"))
						{
							yield return new CodeInstruction(OpCodes.Ldstr, (object)Path.Combine(Paths.GameRootPath, "Renderer"));
						}
						else
						{
							yield return current;
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
			}
		}
	}
	[HarmonyPatch(typeof(RenderSystem), "Initialize")]
	internal class WindowTitlePatcher
	{
		public static void Prefix(Engine engine, ref string? windowTitle)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			if (BepInExResoniteShim.ShowWatermark.Value)
			{
				string bepisLoaderVersion = BepInExResoniteShim.GetBepisLoaderVersion();
				windowTitle = engine.PlatformProfile.Name + " - BepisLoader " + bepisLoaderVersion;
				ManualLogSource log = BepInExResoniteShim.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Successfully patched window title to: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(windowTitle);
				}
				log.LogInfo(val);
			}
		}
	}
	[ResonitePlugin("ResoniteModding.BepInExResoniteShim", "BepInEx Resonite Shim", "0.10.0", "ResoniteModding", "https://github.com/ResoniteModding/BepInExResoniteShim")]
	internal class BepInExResoniteShim : BasePlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ShowWatermark;

		[field: CompilerGenerated]
		internal static bool AnyPatchFailed
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		internal static string? GetBepisLoaderVersion()
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			try
			{
				Assembly val = Enumerable.FirstOrDefault<Assembly>((System.Collections.Generic.IEnumerable<Assembly>)AppDomain.CurrentDomain.GetAssemblies(), (Func<Assembly, bool>)((Assembly a) => a.GetName().Name == "BepisLoader"));
				if (val != (Assembly)null)
				{
					Version version = val.GetName().Version;
					if (version != (Version)null)
					{
						return $"v{version.Major}.{version.Minor}.{version.Build}";
					}
				}
			}
			catch (System.Exception ex)
			{
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(35, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Failed to get BepisLoader version: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				log.LogWarning(val2);
			}
			return null;
		}

		public override void Load()
		{
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_00c4: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			string bepisLoaderVersion = GetBepisLoaderVersion();
			Log.LogInfo((object)((bepisLoaderVersion != null) ? ("Loader: BepisLoader " + bepisLoaderVersion) : "Loader: BepisLoader not found, version unknown"));
			ShowWatermark = ((BasePlugin)this).Config.Bind<bool>("General", "ShowWatermark", true, "Shows 'BepisLoader' watermark in the window title");
			System.Type type = null;
			try
			{
				System.Type[] types = GenericTypesAttribute.GetTypes((Group)1);
				foreach (System.Type type2 in types)
				{
					type = type2;
					if (!TomlTypeConverter.CanConvert(type2))
					{
						TomlTypeConverter.AddConverter(type2, new TypeConverter
						{
							ConvertToString = (object obj, System.Type type3) => (string)((MethodBase)typeof(Coder<>).MakeGenericType(new System.Type[1] { type3 }).GetMethod("EncodeToString")).Invoke((object)null, new object[1] { obj }),
							ConvertToObject = (string str, System.Type type3) => ((MethodBase)typeof(Coder<>).MakeGenericType(new System.Type[1] { type3 }).GetMethod("DecodeFromString")).Invoke((object)null, new object[1] { str })
						});
					}
				}
				type = typeof(dummy);
				TomlTypeConverter.AddConverter(typeof(dummy), new TypeConverter
				{
					ConvertToString = (object _, System.Type _) => "dummy",
					ConvertToObject = (string _, System.Type _) => (object)default(dummy)
				});
			}
			catch (System.Exception ex)
			{
				Log.LogError((object)("Failed to register generic type converters (Last attempted = " + (((object)type)?.ToString() ?? "NULL") + "): " + (object)ex));
			}
			RunPatches(((BasePlugin)this).HarmonyInstance);
		}

		private static void RunPatches(Harmony harmony)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			System.Type[] typesFromAssembly = AccessTools.GetTypesFromAssembly(Assembly.GetExecutingAssembly());
			bool flag = default(bool);
			foreach (System.Type type in typesFromAssembly)
			{
				try
				{
					harmony.CreateClassProcessor(type).Patch();
				}
				catch (System.Exception ex)
				{
					ManualLogSource log = Log;
					BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(19, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Skipped patching ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((MemberInfo)type).Name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					log.LogDebug(val);
					AnyPatchFailed = true;
				}
			}
		}
	}
	public class ResonitePlugin : BepInPlugin
	{
		[field: CompilerGenerated]
		public string Author
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			protected set;
		}

		[field: CompilerGenerated]
		public string Link
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			protected set;
		}

		public ResonitePlugin(string GUID, string Name, string Version, string Author, string Link)
			: base(GUID, Name, Version)
		{
			this.Author = Author;
			this.Link = Link;
		}
	}
	public static class PluginMetadata
	{
		public const string GUID = "ResoniteModding.BepInExResoniteShim";

		public const string NAME = "BepInEx Resonite Shim";

		public const string VERSION = "0.10.0";

		public const string AUTHORS = "ResoniteModding";

		public const string REPOSITORY_URL = "https://github.com/ResoniteModding/BepInExResoniteShim";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class IgnoresAccessChecksToAttribute : System.Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}