Decompiled source of RenderiteHook v1.1.0

plugins/RenderiteHook/RenderiteHook.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using FrooxEngine;
using HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETCoreApp,Version=v9.0", FrameworkDisplayName = ".NET 9.0")]
[assembly: AssemblyCompany("ResoniteModding")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+9d35d0c2ba45ad697901b716fa5e322be2b3d0b9")]
[assembly: AssemblyProduct("RenderiteHook")]
[assembly: AssemblyTitle("RenderiteHook")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/ResoniteModding/RenderiteHook")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace RenderiteHook;

[ResonitePlugin("ResoniteModding.RenderiteHook", "RenderiteHook", "1.1.0", "ResoniteModding", "https://github.com/ResoniteModding/RenderiteHook")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class ArgumentsPatch
	{
		[CompilerGenerated]
		private sealed class <Transpiler>d__0 : 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 bool <patched>5__2;

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

			private CodeInstruction <code>5__4;

			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__0(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();
					}
				}
				<>7__wrap2 = null;
				<code>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<patched>5__2 = false;
						<>7__wrap2 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
					{
						<>1__state = -3;
						object operand = <code>5__4.operand;
						MethodInfo val = (MethodInfo)((operand is MethodInfo) ? operand : null);
						if (val != null && ((MemberInfo)val).Name == "ToStringAndClear")
						{
							<patched>5__2 = true;
							<>2__current = new CodeInstruction(OpCodes.Call, (object)typeof(ArgumentsPatch).GetMethod("OnStartRenderer", (BindingFlags)24));
							<>1__state = 2;
							return true;
						}
						goto IL_00e5;
					}
					case 2:
						{
							<>1__state = -3;
							goto IL_00e5;
						}
						IL_00e5:
						<code>5__4 = null;
						break;
					}
					if (((global::System.Collections.IEnumerator)<>7__wrap2).MoveNext())
					{
						<code>5__4 = <>7__wrap2.Current;
						<>2__current = <code>5__4;
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>7__wrap2 = null;
					if (!<patched>5__2)
					{
						Log.LogError((object)"Failed to patch StartRenderer arguments!");
					}
					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__wrap2 != null)
				{
					((global::System.IDisposable)<>7__wrap2).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__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]
			global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator()
			{
				return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable<CodeInstruction>)this).GetEnumerator();
			}
		}

		[IteratorStateMachine(typeof(<Transpiler>d__0))]
		public static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <Transpiler>d__0(-2)
			{
				<>3__codes = codes
			};
		}

		public static string OnStartRenderer(string args)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			CopyDoorstopFiles(Engine.Current.RenderSystem);
			string originalCommandLineArgs = GetOriginalCommandLineArgs();
			string text = (string.IsNullOrEmpty(originalCommandLineArgs) ? args : (args + " " + originalCommandLineArgs));
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Starting renderer with args: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
			}
			log.LogInfo(val);
			return text;
		}

		private static string GetOriginalCommandLineArgs()
		{
			string text = Environment.CommandLine;
			if (text.StartsWith("\"") && text.Length > 1)
			{
				int num = text.IndexOf("\"", 1);
				if (num != -1)
				{
					text = text.Substring(num + 1).TrimStart();
				}
			}
			else
			{
				int num2 = text.IndexOf(" ");
				if (num2 != -1)
				{
					text = text.Substring(num2 + 1).TrimStart();
				}
			}
			return text;
		}

		private static void CopyDoorstopFiles(RenderSystem renderSystem)
		{
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				if (string.IsNullOrEmpty(directoryName))
				{
					Log.LogError((object)"Could not determine plugin directory");
					return;
				}
				string text = Path.Combine(directoryName, "Doorstop");
				if (!Directory.Exists(text))
				{
					ManualLogSource log = Log;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Doorstop directory not found at: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					}
					log.LogWarning(val);
					return;
				}
				string directoryName2 = Path.GetDirectoryName(renderSystem.RendererPath);
				if (string.IsNullOrEmpty(directoryName2))
				{
					Log.LogError((object)"Could not determine renderer directory");
					return;
				}
				ManualLogSource log2 = Log;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(32, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Copying Doorstop files from ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" to ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(directoryName2);
				}
				log2.LogInfo(val2);
				string[] files = Directory.GetFiles(text, "*", (SearchOption)1);
				foreach (string text2 in files)
				{
					string relativePath = Path.GetRelativePath(text, text2);
					string text3 = Path.Combine(directoryName2, relativePath);
					File.Copy(text2, text3, true);
					ManualLogSource log3 = Log;
					val2 = new BepInExInfoLogInterpolatedStringHandler(8, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Copied: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(relativePath);
					}
					log3.LogInfo(val2);
				}
				Log.LogInfo((object)"Doorstop files copied successfully");
			}
			catch (global::System.Exception ex)
			{
				ManualLogSource log4 = Log;
				BepInExErrorLogInterpolatedStringHandler val3 = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("Failed to copy Doorstop files: ");
					((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
				}
				log4.LogError(val3);
			}
		}
	}

	internal static ManualLogSource Log;

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

	public const string NAME = "RenderiteHook";

	public const string VERSION = "1.1.0";

	public const string AUTHORS = "ResoniteModding";

	public const string REPOSITORY_URL = "https://github.com/ResoniteModding/RenderiteHook";
}