Decompiled source of SaveImagePrompt v1.0.0

plugins/SaveImagePrompt/SaveImagePrompt.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.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using Elements.Core;
using FrooxEngine;
using FrooxEngine.UIX;
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+54ae6c0497419b27e8715876485501e8eb4ed2dd")]
[assembly: AssemblyProduct("SaveImagePrompt")]
[assembly: AssemblyTitle("SaveImagePrompt")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/art0007i/SaveImagePrompt")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace SaveImagePrompt;

[ResonitePlugin("art0007i.SaveImagePrompt", "SaveImagePrompt", "1.0.0", "art0007i", "https://github.com/art0007i/SaveImagePrompt")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BasePlugin
{
	[HarmonyPatch(typeof(PhotoMetadata), "NotifyOfScreenshot")]
	private class SaveImagePromptPatch
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass0_0
		{
			[StructLayout((LayoutKind)3)]
			private struct <<Proxy>b__1>d : IAsyncStateMachine
			{
				public int <>1__state;

				public AsyncTaskMethodBuilder <>t__builder;

				public <>c__DisplayClass0_0 <>4__this;

				private TaskAwaiter<bool> <>u__1;

				private TaskAwaiter <>u__2;

				private void MoveNext()
				{
					//IL_0056: Unknown result type (might be due to invalid IL or missing references)
					//IL_005b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0062: Unknown result type (might be due to invalid IL or missing references)
					//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
					//IL_0023: Unknown result type (might be due to invalid IL or missing references)
					//IL_0028: Unknown result type (might be due to invalid IL or missing references)
					//IL_008b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0090: Unknown result type (might be due to invalid IL or missing references)
					//IL_003c: Unknown result type (might be due to invalid IL or missing references)
					//IL_003d: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
					int num = <>1__state;
					<>c__DisplayClass0_0 <>c__DisplayClass0_ = <>4__this;
					try
					{
						TaskAwaiter val;
						TaskAwaiter<bool> val2;
						if (num != 0)
						{
							if (num == 1)
							{
								val = <>u__2;
								<>u__2 = default(TaskAwaiter);
								num = (<>1__state = -1);
								goto IL_00d6;
							}
							val2 = <>c__DisplayClass0_.tcs.Task.GetAwaiter();
							if (!val2.IsCompleted)
							{
								num = (<>1__state = 0);
								<>u__1 = val2;
								((AsyncTaskMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter<bool>, <<Proxy>b__1>d>(ref val2, ref this);
								return;
							}
						}
						else
						{
							val2 = <>u__1;
							<>u__1 = default(TaskAwaiter<bool>);
							num = (<>1__state = -1);
						}
						if (val2.GetResult())
						{
							val = <>c__DisplayClass0_.worker.StartGlobalTask(<>c__DisplayClass0_.task).GetAwaiter();
							if (!((TaskAwaiter)(ref val)).IsCompleted)
							{
								num = (<>1__state = 1);
								<>u__2 = val;
								((AsyncTaskMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter, <<Proxy>b__1>d>(ref val, ref this);
								return;
							}
							goto IL_00d6;
						}
						goto end_IL_000e;
						IL_00d6:
						((TaskAwaiter)(ref val)).GetResult();
						end_IL_000e:;
					}
					catch (global::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 PhotoMetadata __instance;

			public TaskCompletionSource<bool> tcs;

			public Worker worker;

			public Func<global::System.Threading.Tasks.Task> task;

			public SlotEvent <>9__4;

			internal void <Proxy>b__0()
			{
				//IL_0036: 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_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_016a: 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_018e: Expected O, but got Unknown
				//IL_0193: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Expected O, but got Unknown
				//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Unknown result type (might be due to invalid IL or missing references)
				//IL_0205: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Expected O, but got Unknown
				//IL_020d: Expected O, but got Unknown
				<>c__DisplayClass0_1 CS$<>8__locals7 = new <>c__DisplayClass0_1
				{
					CS$<>8__locals1 = this,
					dialog = Userspace.UserspaceWorld.RootSlot.AddSlot("Save Image Prompt", true)
				};
				UIBuilder obj = RadiantUI_Panel.SetupPanel(CS$<>8__locals7.dialog, LocaleHelper.AsLocaleKey("Save Image?", (string)null, true, (Dictionary<string, object>)null), new float2(400f, 300f), true, true);
				Slot obj2 = CS$<>8__locals7.dialog;
				float3 localScale = obj2.LocalScale;
				obj2.LocalScale = (ref localScale) * 0.0005f;
				RadiantUI_Constants.SetupEditorStyle(obj, false);
				obj.VerticalLayout(4f, 0f, (Alignment?)null, (bool?)null, (bool?)null);
				obj.Style.MinHeight = 64f;
				LocaleString val = LocaleString.op_Implicit($"Would you like to save the image: \"{((Component)__instance).Slot.Name}\" from world \"{((Worker)__instance).World.Name}\"");
				obj.Text(ref val, true, (Alignment?)null, true, (string)null);
				obj.Style.MinHeight = 32f;
				obj.HorizontalLayout(4f, 0f, (Alignment?)null);
				val = LocaleString.op_Implicit("Save");
				colorX? val2 = Sub.GREEN;
				obj.Button(ref val, ref val2).LocalPressed += (ButtonEventHandler)delegate
				{
					CS$<>8__locals7.CS$<>8__locals1.tcs.SetResult(true);
					CS$<>8__locals7.dialog.Destroy();
				};
				val = LocaleString.op_Implicit("Discard");
				val2 = Sub.RED;
				obj.Button(ref val, ref val2).LocalPressed += (ButtonEventHandler)delegate
				{
					CS$<>8__locals7.dialog.Destroy();
				};
				SlotPositioning.PositionInFrontOfUser(CS$<>8__locals7.dialog, (float3?)float3.Backward, (float3?)null, 0.7f, (User)null, true, true, false);
				Slot obj3 = CS$<>8__locals7.dialog;
				SlotEvent obj4 = <>9__4;
				if (obj4 == null)
				{
					SlotEvent val3 = delegate
					{
						_ = ((global::System.Threading.Tasks.Task)tcs.Task).IsCompleted;
						tcs.TrySetResult(false);
					};
					SlotEvent val4 = val3;
					<>9__4 = val3;
					obj4 = val4;
				}
				obj3.OnPrepareDestroy += obj4;
			}

			internal void <Proxy>b__4(Slot s)
			{
				_ = ((global::System.Threading.Tasks.Task)tcs.Task).IsCompleted;
				tcs.TrySetResult(false);
			}

			[AsyncStateMachine(typeof(<<Proxy>b__1>d))]
			internal global::System.Threading.Tasks.Task? <Proxy>b__1()
			{
				//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)
				<<Proxy>b__1>d <<Proxy>b__1>d = default(<<Proxy>b__1>d);
				<<Proxy>b__1>d.<>t__builder = AsyncTaskMethodBuilder.Create();
				<<Proxy>b__1>d.<>4__this = this;
				<<Proxy>b__1>d.<>1__state = -1;
				((AsyncTaskMethodBuilder)(ref <<Proxy>b__1>d.<>t__builder)).Start<<<Proxy>b__1>d>(ref <<Proxy>b__1>d);
				return ((AsyncTaskMethodBuilder)(ref <<Proxy>b__1>d.<>t__builder)).Task;
			}
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass0_1
		{
			public Slot dialog;

			public <>c__DisplayClass0_0 CS$<>8__locals1;

			internal void <Proxy>b__2(IButton b, ButtonEventData e)
			{
				CS$<>8__locals1.tcs.SetResult(true);
				dialog.Destroy();
			}

			internal void <Proxy>b__3(IButton b, ButtonEventData e)
			{
				dialog.Destroy();
			}
		}

		[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 <lookFor>5__2;

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

			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();
					}
				}
				<lookFor>5__2 = null;
				<>7__wrap2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<lookFor>5__2 = AccessTools.FirstMethod(typeof(Worker), (Func<MethodInfo, bool>)((MethodInfo mi) => ((MemberInfo)mi).Name == "StartGlobalTask" && !((MethodBase)mi).IsGenericMethod));
						<>7__wrap2 = codes.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						break;
					case 2:
						<>1__state = -3;
						break;
					}
					if (((global::System.Collections.IEnumerator)<>7__wrap2).MoveNext())
					{
						CodeInstruction current = <>7__wrap2.Current;
						if (CodeInstructionExtensions.Calls(current, <lookFor>5__2))
						{
							<>2__current = new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SaveImagePromptPatch), "Proxy", (global::System.Type[])null, (global::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
					((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__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 global::System.Threading.Tasks.Task Proxy(Worker worker, Func<global::System.Threading.Tasks.Task> task)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			<>c__DisplayClass0_0 CS$<>8__locals15 = new <>c__DisplayClass0_0();
			CS$<>8__locals15.worker = worker;
			CS$<>8__locals15.task = task;
			if (!Enabled.Value)
			{
				return CS$<>8__locals15.worker.StartGlobalTask(CS$<>8__locals15.task);
			}
			CS$<>8__locals15.tcs = new TaskCompletionSource<bool>();
			ref PhotoMetadata reference = ref CS$<>8__locals15.__instance;
			Worker obj = CS$<>8__locals15.worker;
			reference = (PhotoMetadata)(object)((obj is PhotoMetadata) ? obj : null);
			Userspace.UserspaceWorld.RunSynchronously((Action)delegate
			{
				//IL_0036: 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_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_0116: Unknown result type (might be due to invalid IL or missing references)
				//IL_011b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0161: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Unknown result type (might be due to invalid IL or missing references)
				//IL_016a: 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_018e: Expected O, but got Unknown
				//IL_0193: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c0: Expected O, but got Unknown
				//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: Unknown result type (might be due to invalid IL or missing references)
				//IL_0205: Unknown result type (might be due to invalid IL or missing references)
				//IL_0208: Expected O, but got Unknown
				//IL_020d: Expected O, but got Unknown
				<>c__DisplayClass0_0 <>c__DisplayClass0_ = CS$<>8__locals15;
				Slot dialog = Userspace.UserspaceWorld.RootSlot.AddSlot("Save Image Prompt", true);
				UIBuilder obj2 = RadiantUI_Panel.SetupPanel(dialog, LocaleHelper.AsLocaleKey("Save Image?", (string)null, true, (Dictionary<string, object>)null), new float2(400f, 300f), true, true);
				Slot obj3 = dialog;
				float3 localScale = obj3.LocalScale;
				obj3.LocalScale = (ref localScale) * 0.0005f;
				RadiantUI_Constants.SetupEditorStyle(obj2, false);
				obj2.VerticalLayout(4f, 0f, (Alignment?)null, (bool?)null, (bool?)null);
				obj2.Style.MinHeight = 64f;
				LocaleString val = LocaleString.op_Implicit($"Would you like to save the image: \"{((Component)CS$<>8__locals15.__instance).Slot.Name}\" from world \"{((Worker)CS$<>8__locals15.__instance).World.Name}\"");
				obj2.Text(ref val, true, (Alignment?)null, true, (string)null);
				obj2.Style.MinHeight = 32f;
				obj2.HorizontalLayout(4f, 0f, (Alignment?)null);
				val = LocaleString.op_Implicit("Save");
				colorX? val2 = Sub.GREEN;
				obj2.Button(ref val, ref val2).LocalPressed += (ButtonEventHandler)delegate
				{
					<>c__DisplayClass0_.tcs.SetResult(true);
					dialog.Destroy();
				};
				val = LocaleString.op_Implicit("Discard");
				val2 = Sub.RED;
				obj2.Button(ref val, ref val2).LocalPressed += (ButtonEventHandler)delegate
				{
					dialog.Destroy();
				};
				SlotPositioning.PositionInFrontOfUser(dialog, (float3?)float3.Backward, (float3?)null, 0.7f, (User)null, true, true, false);
				Slot obj4 = dialog;
				SlotEvent obj5 = CS$<>8__locals15.<>9__4;
				if (obj5 == null)
				{
					SlotEvent val3 = delegate
					{
						_ = ((global::System.Threading.Tasks.Task)CS$<>8__locals15.tcs.Task).IsCompleted;
						CS$<>8__locals15.tcs.TrySetResult(false);
					};
					SlotEvent val4 = val3;
					CS$<>8__locals15.<>9__4 = val3;
					obj5 = val4;
				}
				obj4.OnPrepareDestroy += obj5;
			}, false, (IUpdatable)null, false);
			return global::System.Threading.Tasks.Task.Run((Func<global::System.Threading.Tasks.Task>)([AsyncStateMachine(typeof(<>c__DisplayClass0_0.<<Proxy>b__1>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__DisplayClass0_0.<<Proxy>b__1>d <<Proxy>b__1>d = default(<>c__DisplayClass0_0.<<Proxy>b__1>d);
				<<Proxy>b__1>d.<>t__builder = AsyncTaskMethodBuilder.Create();
				<<Proxy>b__1>d.<>4__this = CS$<>8__locals15;
				<<Proxy>b__1>d.<>1__state = -1;
				((AsyncTaskMethodBuilder)(ref <<Proxy>b__1>d.<>t__builder)).Start<<>c__DisplayClass0_0.<<Proxy>b__1>d>(ref <<Proxy>b__1>d);
				return ((AsyncTaskMethodBuilder)(ref <<Proxy>b__1>d.<>t__builder)).Task;
			}));
		}

		[IteratorStateMachine(typeof(<Transpiler>d__1))]
		public static global::System.Collections.Generic.IEnumerable<CodeInstruction> Transpiler(global::System.Collections.Generic.IEnumerable<CodeInstruction> codes)
		{
			MethodInfo lookFor = AccessTools.FirstMethod(typeof(Worker), (Func<MethodInfo, bool>)((MethodInfo mi) => ((MemberInfo)mi).Name == "StartGlobalTask" && !((MethodBase)mi).IsGenericMethod));
			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, lookFor))
					{
						yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(SaveImagePromptPatch), "Proxy", (global::System.Type[])null, (global::System.Type[])null));
					}
					else
					{
						yield return current;
					}
				}
			}
			finally
			{
				((global::System.IDisposable)enumerator)?.Dispose();
			}
		}
	}

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> Enabled;

	public override void Load()
	{
		Log = ((BasePlugin)this).Log;
		Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Should the mod be enabled?");
		((BasePlugin)this).HarmonyInstance.PatchAll();
	}
}
public static class PluginMetadata
{
	public const string GUID = "art0007i.SaveImagePrompt";

	public const string NAME = "SaveImagePrompt";

	public const string VERSION = "1.0.0";

	public const string AUTHORS = "art0007i";

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