using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Threading.Tasks; using BepInEx; using BepInEx.Logging; using BepInEx.NET.Common; using BepInExResoniteShim; using Elements.Core; using FrooxEngine; using FrooxEngine.ProtoFlux; using HarmonyLib; using ProtoFlux.Core; using ProtoFlux.Runtimes.Execution; using ProtoFlux.Runtimes.Execution.Nodes.FrooxEngine.Rendering; using Renderite.Shared; using SkyFrost.Base; [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.2.0")] [assembly: AssemblyInformationalVersion("1.0.2+1862240c560ad309e79c95d7db5d324093ce12d5")] [assembly: AssemblyProduct("SimplePictureCapture")] [assembly: AssemblyTitle("SimplePictureCapture")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/art0007i/SimplePictureCapture")] [assembly: AssemblyVersion("1.0.2.0")] [module: RefSafetyRules(11)] namespace SimplePictureCapture; [ResonitePlugin("art0007i.SimplePictureCapture", "SimplePictureCapture", "1.0.2", "art0007i", "https://github.com/art0007i/SimplePictureCapture")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BasePlugin { [HarmonyPatch(typeof(RenderToTextureAsset), "RunAsync")] private class SimplePictureCapturePatch { [CompilerGenerated] private sealed class <>c__DisplayClass0_0 { [StructLayout((LayoutKind)3)] private struct <b__0>d : IAsyncStateMachine { public int <>1__state; public AsyncTaskMethodBuilder <>t__builder; public <>c__DisplayClass0_0 <>4__this; private <>c__DisplayClass0_1 <>8__1; private TaskAwaiter <>u__1; private void MoveNext() { //IL_01c7: Unknown result type (might be due to invalid IL or missing references) //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d4: Unknown result type (might be due to invalid IL or missing references) //IL_004b: 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_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0060: 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_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0089: 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_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0216: Expected O, but got Unknown //IL_0110: Unknown result type (might be due to invalid IL or missing references) //IL_0115: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0192: Unknown result type (might be due to invalid IL or missing references) //IL_0197: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Unknown result type (might be due to invalid IL or missing references) int num = <>1__state; <>c__DisplayClass0_0 <>c__DisplayClass0_ = <>4__this; IOperation target; try { TaskAwaiter val; if (num == 0) { val = <>u__1; <>u__1 = default(TaskAwaiter); num = (<>1__state = -1); goto IL_01e3; } <>8__1 = new <>c__DisplayClass0_1(); <>8__1.CS$<>8__locals1 = <>c__DisplayClass0_; <>8__1.world = Engine.Current.WorldManager.FocusedWorld; int2 val2 = ExecutionContextExtensions.Evaluate(<>c__DisplayClass0_.__instance.Resolution, (ExecutionContext)(object)<>c__DisplayClass0_.context, default(int2)); string text = ExecutionContextExtensions.Evaluate(<>c__DisplayClass0_.__instance.Format, (ExecutionContext)(object)<>c__DisplayClass0_.context, "webp"); int num2 = ExecutionContextExtensions.Evaluate(<>c__DisplayClass0_.__instance.Quality, (ExecutionContext)(object)<>c__DisplayClass0_.context, 200); RenderTask renderSettings = <>c__DisplayClass0_.cam.GetRenderSettings(val2); if (!WorldExtensions.IsUserspace(((Worker)<>c__DisplayClass0_.cam).World)) { goto IL_0134; } UserRoot root = <>8__1.world.LocalUser.Root; if (root != null) { renderSettings.position = ((Component)root).Slot.LocalPointToGlobal(ref renderSettings.position); renderSettings.rotation = ((Component)root).Slot.LocalRotationToGlobal(ref renderSettings.rotation); goto IL_0134; } Log.LogError((object)"You have no user root? How did you click the button wtf"); target = ((Continuation)(ref <>c__DisplayClass0_.__instance.OnFailed)).Target; goto end_IL_000e; IL_01e3: Uri result = val.GetResult(); <>8__1.texture = result; ((ComponentBase)(object)<>c__DisplayClass0_.cam).RunSynchronously((Action)([AsyncStateMachine(typeof(<>c__DisplayClass0_1.<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_1.<b__1>d <b__1>d = default(<>c__DisplayClass0_1.<b__1>d); <b__1>d.<>t__builder = AsyncVoidMethodBuilder.Create(); <b__1>d.<>4__this = <>8__1; <b__1>d.<>1__state = -1; ((AsyncVoidMethodBuilder)(ref <b__1>d.<>t__builder)).Start<<>c__DisplayClass0_1.<b__1>d>(ref <b__1>d); }), false); if (<>8__1.texture != (Uri)null) { ExecutionContextExtensions.Write(<>c__DisplayClass0_.__instance.RenderedAssetURL, <>8__1.texture, (ExecutionContext)(object)<>c__DisplayClass0_.context); target = ((Continuation)(ref <>c__DisplayClass0_.__instance.OnRendered)).Target; } else { target = ((Continuation)(ref <>c__DisplayClass0_.__instance.OnFailed)).Target; } goto end_IL_000e; IL_0134: if (renderSettings.excludeObjects == null || WorldExtensions.IsUserspace(((Worker)<>c__DisplayClass0_.cam).World)) { renderSettings.excludeObjects = new List(); } InteractionHandler.GetLaserRoots((global::System.Collections.Generic.IEnumerable)<>8__1.world.AllUsers, renderSettings.excludeObjects); val = <>8__1.world.Render.RenderToAsset(renderSettings, text, num2).GetAwaiter(); if (!val.IsCompleted) { num = (<>1__state = 0); <>u__1 = val; <>t__builder.AwaitUnsafeOnCompleted, <b__0>d>(ref val, ref this); return; } goto IL_01e3; end_IL_000e:; } catch (global::System.Exception exception) { <>1__state = -2; <>8__1 = null; <>t__builder.SetException(exception); return; } <>1__state = -2; <>8__1 = null; <>t__builder.SetResult(target); } [DebuggerHidden] private void SetStateMachine(IAsyncStateMachine stateMachine) { <>t__builder.SetStateMachine(stateMachine); } } public RenderToTextureAsset __instance; public FrooxEngineContext context; public Camera cam; [AsyncStateMachine(typeof(<b__0>d))] internal async global::System.Threading.Tasks.Task? 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) <>c__DisplayClass0_1 CS$<>8__locals7 = new <>c__DisplayClass0_1 { CS$<>8__locals1 = this, world = Engine.Current.WorldManager.FocusedWorld }; int2 val = ExecutionContextExtensions.Evaluate(__instance.Resolution, (ExecutionContext)(object)context, default(int2)); string text = ExecutionContextExtensions.Evaluate(__instance.Format, (ExecutionContext)(object)context, "webp"); int num = ExecutionContextExtensions.Evaluate(__instance.Quality, (ExecutionContext)(object)context, 200); RenderTask renderSettings = cam.GetRenderSettings(val); if (WorldExtensions.IsUserspace(((Worker)cam).World)) { UserRoot root = CS$<>8__locals7.world.LocalUser.Root; if (root == null) { Log.LogError((object)"You have no user root? How did you click the button wtf"); return ((Continuation)(ref __instance.OnFailed)).Target; } renderSettings.position = ((Component)root).Slot.LocalPointToGlobal(ref renderSettings.position); renderSettings.rotation = ((Component)root).Slot.LocalRotationToGlobal(ref renderSettings.rotation); } if (renderSettings.excludeObjects == null || WorldExtensions.IsUserspace(((Worker)cam).World)) { renderSettings.excludeObjects = new List(); } InteractionHandler.GetLaserRoots((global::System.Collections.Generic.IEnumerable)CS$<>8__locals7.world.AllUsers, renderSettings.excludeObjects); CS$<>8__locals7.texture = await CS$<>8__locals7.world.Render.RenderToAsset(renderSettings, text, num); ((ComponentBase)(object)cam).RunSynchronously((Action)([AsyncStateMachine(typeof(<>c__DisplayClass0_1.<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_1.<b__1>d <b__1>d = default(<>c__DisplayClass0_1.<b__1>d); <b__1>d.<>t__builder = AsyncVoidMethodBuilder.Create(); <b__1>d.<>4__this = CS$<>8__locals7; <b__1>d.<>1__state = -1; ((AsyncVoidMethodBuilder)(ref <b__1>d.<>t__builder)).Start<<>c__DisplayClass0_1.<b__1>d>(ref <b__1>d); }), false); if (CS$<>8__locals7.texture != (Uri)null) { ExecutionContextExtensions.Write(__instance.RenderedAssetURL, CS$<>8__locals7.texture, (ExecutionContext)(object)context); return ((Continuation)(ref __instance.OnRendered)).Target; } return ((Continuation)(ref __instance.OnFailed)).Target; } } [CompilerGenerated] private sealed class <>c__DisplayClass0_1 { [StructLayout((LayoutKind)3)] private struct <b__1>d : IAsyncStateMachine { public int <>1__state; public AsyncVoidMethodBuilder <>t__builder; public <>c__DisplayClass0_1 <>4__this; private Slot 5__2; private bool 5__3; private TaskAwaiter <>u__1; private void MoveNext() { //IL_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: Unknown result type (might be due to invalid IL or missing references) //IL_029f: Unknown result type (might be due to invalid IL or missing references) //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_010b: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_011d: Unknown result type (might be due to invalid IL or missing references) //IL_0158: Unknown result type (might be due to invalid IL or missing references) //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0250: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01f8: Unknown result type (might be due to invalid IL or missing references) //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Unknown result type (might be due to invalid IL or missing references) //IL_021f: Unknown result type (might be due to invalid IL or missing references) //IL_022f: Unknown result type (might be due to invalid IL or missing references) //IL_0260: Unknown result type (might be due to invalid IL or missing references) //IL_0265: Unknown result type (might be due to invalid IL or missing references) //IL_027a: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) int num = <>1__state; <>c__DisplayClass0_1 <>c__DisplayClass0_ = <>4__this; try { TaskAwaiter val5; if (num != 0) { 5__2 = ((Worker)<>c__DisplayClass0_.CS$<>8__locals1.cam).LocalUserSpace.AddSlot("Photo in " + <>c__DisplayClass0_.world.Name, true); StaticTexture2D val = SlotAssets.AttachTexture(5__2, <>c__DisplayClass0_.texture, true, false, false, false, (TextureWrapMode)0, (int?)null); ImageImporter.SetupTextureProxyComponents(5__2, (IAssetProvider)(object)val, (StereoLayout)0, (ImageProjection)0, false); PhotoMetadata obj = ((ContainerWorker)(object)5__2).AttachComponent(true, (Action)null); SetupMetadataFromWorld(obj, <>c__DisplayClass0_.world); ((SyncField)(object)obj.Is360).Value = false; ((SyncField)(object)obj.StereoLayout).Value = (StereoLayout)0; ((SyncField)(object)obj.CameraManufacturer).Value = "art0007i"; ((SyncField)(object)obj.CameraModel).Value = "SimplePictureCapture Mod"; ((SyncField)(object)obj.CameraFOV).Value = Sync.op_Implicit(<>c__DisplayClass0_.CS$<>8__locals1.cam.FieldOfView); ((SyncField)(object)((ContainerWorker)(object)5__2).AttachComponent(true, (Action)null).Scalable).Value = true; AttachedModel val2 = SlotMeshes.AttachMesh(5__2, false, 0); ((SyncRef>)(object)val2.material.Texture).Target = (IAssetProvider)(object)val; ((SyncField)(object)val2.material.Sidedness).Value = (Sidedness)3; TextureSizeDriver obj2 = ((ContainerWorker)(object)5__2).AttachComponent(true, (Action)null); ((SyncRef>)(object)obj2.Texture).Target = (IAssetProvider)(object)val; ((SyncField)(object)obj2.DriveMode).Value = (Mode)3; ((SyncRef>)(object)obj2.Target).Target = (IField)(object)val2.mesh.Size; BoxCollider obj3 = ((ContainerWorker)(object)5__2).AttachComponent(true, (Action)null); Float2ToFloat3SwizzleDriverExtensions.DriveFromXY((IField)(object)obj3.Size, (IField)(object)val2.mesh.Size, 0, 1, -1); ((SyncField)(object)((Collider)obj3).Type).Value = (ColliderType)0; Slot val3 = (((Worker)<>c__DisplayClass0_.CS$<>8__locals1.cam).IsRemoved ? null : Enumerable.FirstOrDefault((global::System.Collections.Generic.IEnumerable)<>c__DisplayClass0_.CS$<>8__locals1.cam.ExcludeRender)); 5__3 = val3 == null; if (!5__3) { int childrenCount = val3.ChildrenCount; float3 val4 = new float3(0f, 0f, 0.05f); float3 localPosition = childrenCount * (ref val4); 5__2.Parent = val3; 5__2.LocalPosition = localPosition; 5__2.LocalRotation = floatQ.Identity; 5__2.LocalScale = float3.One; } else { 5__2.LocalPosition = new float3(0f, -10000f, 0f); } val5 = obj.NotifyOfScreenshot(true).GetAwaiter(); if (!((TaskAwaiter)(ref val5)).IsCompleted) { num = (<>1__state = 0); <>u__1 = val5; ((AsyncVoidMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompletedb__1>d>(ref val5, ref this); return; } } else { val5 = <>u__1; <>u__1 = default(TaskAwaiter); num = (<>1__state = -1); } ((TaskAwaiter)(ref val5)).GetResult(); if (5__3) { 5__2.Destroy(); } } catch (global::System.Exception exception) { <>1__state = -2; 5__2 = null; ((AsyncVoidMethodBuilder)(ref <>t__builder)).SetException(exception); return; } <>1__state = -2; 5__2 = null; ((AsyncVoidMethodBuilder)(ref <>t__builder)).SetResult(); } [DebuggerHidden] private void SetStateMachine(IAsyncStateMachine stateMachine) { ((AsyncVoidMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine); } } public World world; public Uri texture; public <>c__DisplayClass0_0 CS$<>8__locals1; [AsyncStateMachine(typeof(<b__1>d))] internal void 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) <b__1>d <b__1>d = default(<b__1>d); <b__1>d.<>t__builder = AsyncVoidMethodBuilder.Create(); <b__1>d.<>4__this = this; <b__1>d.<>1__state = -1; ((AsyncVoidMethodBuilder)(ref <b__1>d.<>t__builder)).Start<<b__1>d>(ref <b__1>d); } } public static bool Prefix(RenderToTextureAsset __instance, FrooxEngineContext context, ref global::System.Threading.Tasks.Task __result) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) Camera cam = ExecutionContextExtensions.Evaluate(__instance.Camera, (ExecutionContext)(object)context, (Camera)null); Camera obj = cam; if (((obj == null) ? null : ((SyncField)(object)((ContainerWorker)(object)((Component)obj).Slot).GetComponent((Predicate)null, false)?.Text).Value) == "me.art0007i.SimplePictureCapture") { <>c__DisplayClass0_0 CS$<>8__locals2; __result = global::System.Threading.Tasks.Task.Run((Func>)([AsyncStateMachine(typeof(<>c__DisplayClass0_0.<b__0>d))] async () => { //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_1 CS$<>8__locals10 = new <>c__DisplayClass0_1(); CS$<>8__locals10.CS$<>8__locals1 = CS$<>8__locals2; CS$<>8__locals10.world = Engine.Current.WorldManager.FocusedWorld; int2 val = ExecutionContextExtensions.Evaluate(__instance.Resolution, (ExecutionContext)(object)context, default(int2)); string text = ExecutionContextExtensions.Evaluate(__instance.Format, (ExecutionContext)(object)context, "webp"); int num = ExecutionContextExtensions.Evaluate(__instance.Quality, (ExecutionContext)(object)context, 200); RenderTask renderSettings = cam.GetRenderSettings(val); if (WorldExtensions.IsUserspace(((Worker)cam).World)) { UserRoot root = CS$<>8__locals10.world.LocalUser.Root; if (root == null) { Log.LogError((object)"You have no user root? How did you click the button wtf"); return ((Continuation)(ref __instance.OnFailed)).Target; } renderSettings.position = ((Component)root).Slot.LocalPointToGlobal(ref renderSettings.position); renderSettings.rotation = ((Component)root).Slot.LocalRotationToGlobal(ref renderSettings.rotation); } if (renderSettings.excludeObjects == null || WorldExtensions.IsUserspace(((Worker)cam).World)) { renderSettings.excludeObjects = new List(); } InteractionHandler.GetLaserRoots((global::System.Collections.Generic.IEnumerable)CS$<>8__locals10.world.AllUsers, renderSettings.excludeObjects); CS$<>8__locals10.texture = await CS$<>8__locals10.world.Render.RenderToAsset(renderSettings, text, num); ((ComponentBase)(object)cam).RunSynchronously((Action)([AsyncStateMachine(typeof(<>c__DisplayClass0_1.<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_1.<b__1>d <b__1>d = default(<>c__DisplayClass0_1.<b__1>d); <b__1>d.<>t__builder = AsyncVoidMethodBuilder.Create(); <b__1>d.<>4__this = CS$<>8__locals10; <b__1>d.<>1__state = -1; ((AsyncVoidMethodBuilder)(ref <b__1>d.<>t__builder)).Start<<>c__DisplayClass0_1.<b__1>d>(ref <b__1>d); }), false); if (CS$<>8__locals10.texture != (Uri)null) { ExecutionContextExtensions.Write(__instance.RenderedAssetURL, CS$<>8__locals10.texture, (ExecutionContext)(object)context); return ((Continuation)(ref __instance.OnRendered)).Target; } return ((Continuation)(ref __instance.OnFailed)).Target; })); return false; } return true; } public static void SetupMetadataFromWorld(PhotoMetadata meta, World wld) { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_009c: 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_010e: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0156: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Unknown result type (might be due to invalid IL or missing references) //IL_0182: Unknown result type (might be due to invalid IL or missing references) ((SyncField)(object)((AssetMetadata)meta).LocationName).Value = wld.Name; ((SyncField)(object)((AssetMetadata)meta).LocationURL).Value = wld.RecordURL; ((AssetMetadata)meta).LocationHost.Target = wld.HostUser; ((SyncField)(object)((AssetMetadata)meta).LocationAccessLevel).Value = wld.AccessLevel; ((SyncField)(object)((AssetMetadata)meta).LocationHiddenFromListing).Value = wld.HideFromListing; ((SyncField)(object)((AssetMetadata)meta).TimeTaken).Value = global::System.DateTime.UtcNow; ((AssetMetadata)meta).TakenBy.Target = ((Worker)meta).LocalUser; ((SyncField)(object)((AssetMetadata)meta).AppVersion).Value = ((Worker)meta).Engine.VersionString; Enumerator enumerator = wld.AllUsers.GetEnumerator(); try { while (enumerator.MoveNext()) { User current = enumerator.Current; UserInfo val = ((SyncElementList)(object)((AssetMetadata)meta).UserInfos).Add(); val.User.Target = current; ((SyncField)(object)val.SessionJoinTimestamp).Value = current.SessionJoinTimestamp; ((SyncField)(object)val.IsPresent).Value = current.IsPresent; ((SyncField)(object)val.IsInVR).Value = current.VR_Active; if (current.Root != null) { ((SyncField)(object)val.HeadPosition).Value = current.Root.HeadPosition; ((SyncField)(object)val.HeadOrientation).Value = current.Root.HeadRotation; } } } finally { ((global::System.IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose(); } ((SyncField)(object)((AssetMetadata)meta).TakenGlobalPosition).Value = ((Component)meta).Slot.GlobalPosition; ((SyncField)(object)((AssetMetadata)meta).TakenGlobalRotation).Value = ((Component)meta).Slot.GlobalRotation; ((SyncField)(object)((AssetMetadata)meta).TakenGlobalScale).Value = ((Component)meta).Slot.GlobalScale; } } 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.SimplePictureCapture"; public const string NAME = "SimplePictureCapture"; public const string VERSION = "1.0.2"; public const string AUTHORS = "art0007i"; public const string REPOSITORY_URL = "https://github.com/art0007i/SimplePictureCapture"; }