Decompiled source of ReFract Reloaded v1.1.0

plugins/ReFract.FrooxEngine/ReFract_FrooxEngine.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.NET.Common;
using BepInExResoniteShim;
using BepisResoniteWrapper;
using Elements.Core;
using FrooxEngine;
using HarmonyLib;
using InterprocessLib;
using ReFract.Shared;
using Renderite.Shared;

[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("Noble, yosh, pocoworks, Cyro")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+53860b674ee7122ede15f66d63210c4a0006cffb")]
[assembly: AssemblyProduct("Re:Fract // Reloaded")]
[assembly: AssemblyTitle("ReFract_FrooxEngine")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/noblereign/ReFract-ReLoaded")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace ReFract
{
	public static class CameraHelperFunctions
	{
		private static readonly FieldInfo _dynamicValuesField = typeof(DynamicVariableSpace).GetField("_dynamicValues", (BindingFlags)36);

		private static readonly FieldInfo _handlerField = typeof(DynamicReferenceVariable<Camera>).BaseType.GetField("handler", (BindingFlags)36);

		public static void SetCameraVariable<T>(DynamicVariableSpace space, string camName, string componentName, string paramName, T value)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Expected O, but got Unknown
			if (Plugin._messenger == null || space == null)
			{
				return;
			}
			Camera val = default(Camera);
			bool flag = default(bool);
			if (!space.TryReadValue<Camera>(Plugin.DynVarCamKeyString + camName, ref val))
			{
				ManualLogSource log = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(45, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Could not find camera variable for ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
				}
				log.LogWarning(val2);
				return;
			}
			Camera val3 = val;
			if (val3 == null)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Camera for ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is null");
				}
				log2.LogWarning(val2);
				return;
			}
			IAssetProvider<RenderTexture> target = ((SyncRef<IAssetProvider<RenderTexture>>)(object)val3.RenderTexture).Target;
			if (target == null)
			{
				ManualLogSource log3 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Render texture for camera ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is null");
				}
				log3.LogWarning(val2);
				return;
			}
			int assetId = ((DynamicRendererAsset<RenderTexture>)(object)target.Asset).AssetId;
			if (assetId == 0)
			{
				ManualLogSource log4 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(53, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Asset ID for render texture of camera ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is 0");
				}
				log4.LogWarning(val2);
				return;
			}
			ReFractCommand reFractCommand = new ReFractCommand
			{
				RenderTextureId = assetId,
				CameraName = camName,
				ComponentName = componentName,
				ParameterName = paramName
			};
			if (value is int)
			{
				object obj = value;
				int intValue = (int)((obj is int) ? obj : null);
				reFractCommand.ValueType = ReFractCommandValueType.Int;
				reFractCommand.IntValue = intValue;
			}
			else if (value is float)
			{
				object obj2 = value;
				float floatValue = (float)((obj2 is float) ? obj2 : null);
				reFractCommand.ValueType = ReFractCommandValueType.Float;
				reFractCommand.FloatValue = floatValue;
			}
			else if (value is bool)
			{
				object obj3 = value;
				bool boolValue = (bool)((obj3 is bool) ? obj3 : null);
				reFractCommand.ValueType = ReFractCommandValueType.Bool;
				reFractCommand.BoolValue = boolValue;
			}
			else if (value is color)
			{
				object obj4 = value;
				color val4 = (color)((obj4 is color) ? obj4 : null);
				reFractCommand.ValueType = ReFractCommandValueType.Color;
				reFractCommand.ColorValue = new ReFractColor
				{
					r = val4.r,
					g = val4.g,
					b = val4.b,
					a = val4.a
				};
			}
			else if (value is float2)
			{
				object obj5 = value;
				float2 val5 = (float2)((obj5 is float2) ? obj5 : null);
				reFractCommand.ValueType = ReFractCommandValueType.Vector2;
				reFractCommand.Vector2Value = new ReFractVector2
				{
					x = val5.x,
					y = val5.y
				};
			}
			else if (value is float4)
			{
				object obj6 = value;
				float4 val6 = (float4)((obj6 is float4) ? obj6 : null);
				reFractCommand.ValueType = ReFractCommandValueType.Vector4;
				reFractCommand.Vector4Value = new ReFractVector4
				{
					x = val6.x,
					y = val6.y,
					z = val6.z,
					w = val6.w
				};
			}
			else
			{
				if (!(value is string stringValue))
				{
					ManualLogSource log5 = Plugin.Log;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(41, 4, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Unsupported value type for ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("/");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(componentName);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("/");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(paramName);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<global::System.Type>(typeof(T));
					}
					log5.LogWarning(val2);
					return;
				}
				reFractCommand.ValueType = ReFractCommandValueType.String;
				reFractCommand.StringValue = stringValue;
			}
			Plugin._messenger.SendObject<ReFractCommand>("SetVariable", reFractCommand);
		}

		public static void SetRemoveAlpha(DynamicVariableSpace space, string camName, bool enabled)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Expected O, but got Unknown
			if (Plugin._messenger == null || space == null)
			{
				return;
			}
			Camera val = default(Camera);
			bool flag = default(bool);
			if (!space.TryReadValue<Camera>(Plugin.DynVarCamKeyString + camName, ref val))
			{
				ManualLogSource log = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(64, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Could not find camera variable for ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" to set RemoveAlpha");
				}
				log.LogWarning(val2);
				return;
			}
			Camera val3 = val;
			if (val3 == null)
			{
				ManualLogSource log2 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(29, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Camera for ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is null");
				}
				log2.LogWarning(val2);
				return;
			}
			IAssetProvider<RenderTexture> target = ((SyncRef<IAssetProvider<RenderTexture>>)(object)val3.RenderTexture).Target;
			if (target == null)
			{
				ManualLogSource log3 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(44, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Render texture for camera ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is null");
				}
				log3.LogWarning(val2);
				return;
			}
			int assetId = ((DynamicRendererAsset<RenderTexture>)(object)target.Asset).AssetId;
			if (assetId == 0)
			{
				ManualLogSource log4 = Plugin.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(53, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Re:Fract: Asset ID for render texture of camera ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(camName);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is 0");
				}
				log4.LogWarning(val2);
				return;
			}
			ReFractCommand reFractCommand = new ReFractCommand
			{
				RenderTextureId = assetId,
				IsRemoveAlphaCommand = true,
				BoolValue = enabled,
				ValueType = ReFractCommandValueType.Bool
			};
			ManualLogSource log5 = Plugin.Log;
			BepInExDebugLogInterpolatedStringHandler val4 = new BepInExDebugLogInterpolatedStringHandler(51, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Re:Fract: Sending RemoveAlpha command for ");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(camName);
				((BepInExLogInterpolatedStringHandler)val4).AppendLiteral(", value: ");
				((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<bool>(enabled);
			}
			log5.LogDebug(val4);
			Plugin._messenger.SendObject<ReFractCommand>("SetVariable", reFractCommand);
		}

		public static void SetRemoveAlphaGlobal(DynamicVariableSpace space, bool enabled)
		{
			if (_dynamicValuesField == (FieldInfo)null)
			{
				return;
			}
			object value = _dynamicValuesField.GetValue((object)space);
			IDictionary val = (IDictionary)((value is IDictionary) ? value : null);
			if (val == null)
			{
				return;
			}
			foreach (object item in (global::System.Collections.IEnumerable)val.Keys)
			{
				FieldInfo field = item.GetType().GetField("name");
				string text = ((field != null) ? field.GetValue(item) : null) as string;
				if (!string.IsNullOrEmpty(text) && text.StartsWith(Plugin.DynVarCamKeyString))
				{
					string camName = text.Substring(Plugin.DynVarCamKeyString.Length);
					SetRemoveAlpha(space, camName, enabled);
				}
			}
		}

		public static void RefreshCameraState(DynamicReferenceVariable<Camera> camVar, Camera camera)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Expected O, but got Unknown
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Expected O, but got Unknown
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Expected O, but got Unknown
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExMessageLogInterpolatedStringHandler val = new BepInExMessageLogInterpolatedStringHandler(19, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Re:Fract: Reset ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Worker)camera).Name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<RefID>(((Worker)camera).ReferenceID);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
			}
			log.LogMessage(val);
			string[] array = Sync<string>.op_Implicit(((DynamicVariableBase<Camera>)(object)camVar).VariableName).Split('_', (StringSplitOptions)0);
			if (_handlerField == (FieldInfo)null)
			{
				Plugin.Log.LogWarning((object)"Re:Fract: Could not find handler field on DynamicReferenceVariable.");
				return;
			}
			DynamicVariableHandler<Camera> val2 = _handlerField.GetValue((object)camVar) as DynamicVariableHandler<Camera>;
			if (val2?.CurrentSpace == null || _dynamicValuesField == (FieldInfo)null)
			{
				return;
			}
			object value = _dynamicValuesField.GetValue((object)val2.CurrentSpace);
			IDictionary val3 = (IDictionary)((value is IDictionary) ? value : null);
			if (val3 == null)
			{
				return;
			}
			foreach (object item in (global::System.Collections.IEnumerable)val3.Keys)
			{
				FieldInfo field = item.GetType().GetField("name");
				if (!(((field != null) ? field.GetValue(item) : null) is string text))
				{
					continue;
				}
				string[] array2 = text.Split('_', (StringSplitOptions)0);
				if (array.Length != 3 || !(array[0] == "Re.Fract") || !(array[1] == "Camera"))
				{
					continue;
				}
				string text2 = array[2];
				if (array2.Length == 4 && array2[0] == "Re.Fract" && array2[1] == text2)
				{
					object obj = val3[item];
					object obj2;
					if (obj == null)
					{
						obj2 = null;
					}
					else
					{
						PropertyInfo property = obj.GetType().GetProperty("Value");
						obj2 = ((property != null) ? property.GetValue(val3[item]) : null);
					}
					object obj3 = obj2;
					if (obj3 != null)
					{
						ManualLogSource log2 = Plugin.Log;
						BepInExDebugLogInterpolatedStringHandler val4 = new BepInExDebugLogInterpolatedStringHandler(37, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Re:Fract: Refreshing '");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("' for camera '");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text2);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("'");
						}
						log2.LogDebug(val4);
						MethodInfo method = typeof(CameraHelperFunctions).GetMethod("SetCameraVariable");
						if (!(method == (MethodInfo)null))
						{
							((MethodBase)method.MakeGenericMethod(new global::System.Type[1] { obj3.GetType() })).Invoke((object)null, new object[5]
							{
								val2.CurrentSpace,
								text2,
								array2[2],
								array2[3],
								obj3
							});
						}
					}
				}
				else if (array2.Length == 3 && array2[0] == "Re.Fract" && array2[1] == text2 && array2[2] == "RemoveAlpha")
				{
					object obj4 = val3[item];
					object obj5;
					if (obj4 == null)
					{
						obj5 = null;
					}
					else
					{
						PropertyInfo property2 = obj4.GetType().GetProperty("Value");
						obj5 = ((property2 != null) ? property2.GetValue(val3[item]) : null);
					}
					if (obj5 is bool enabled)
					{
						ManualLogSource log3 = Plugin.Log;
						BepInExDebugLogInterpolatedStringHandler val4 = new BepInExDebugLogInterpolatedStringHandler(48, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Re:Fract: Refreshing 'RemoveAlpha' for camera '");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text2);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("'");
						}
						log3.LogDebug(val4);
						SetRemoveAlpha(val2.CurrentSpace, text2, enabled);
					}
				}
				else
				{
					if (array2.Length != 2 || !(array2[0] == "Re.Fract") || !(array2[1] == "RemoveAlpha"))
					{
						continue;
					}
					object obj6 = val3[item];
					object obj7;
					if (obj6 == null)
					{
						obj7 = null;
					}
					else
					{
						PropertyInfo property3 = obj6.GetType().GetProperty("Value");
						obj7 = ((property3 != null) ? property3.GetValue(val3[item]) : null);
					}
					if (obj7 is bool enabled2)
					{
						ManualLogSource log4 = Plugin.Log;
						BepInExDebugLogInterpolatedStringHandler val4 = new BepInExDebugLogInterpolatedStringHandler(55, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("Re:Fract: Refreshing global 'RemoveAlpha' for camera '");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(text2);
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("'");
						}
						log4.LogDebug(val4);
						SetRemoveAlpha(val2.CurrentSpace, text2, enabled2);
					}
				}
			}
		}
	}
	public static class DelegateExtensions
	{
		public static bool HasSubscriber(this global::System.Delegate source, global::System.Delegate target)
		{
			if (source == null)
			{
				return false;
			}
			if (target == null)
			{
				return false;
			}
			global::System.Delegate[] invocationList = source.GetInvocationList();
			for (int i = 0; i < invocationList.Length; i++)
			{
				if (((object)invocationList[i]).Equals((object)target))
				{
					return true;
				}
			}
			return false;
		}
	}
	[ResonitePlugin("dog.glacier.ReFract", "Re:Fract // Reloaded", "1.1.0", "Noble, yosh, pocoworks, Cyro", "https://github.com/noblereign/ReFract-ReLoaded")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		[HarmonyPatch(typeof(RenderSystem), "HandleCommand")]
		private class RenderSystem_HandleCommand_Patch
		{
			public static void Postfix(RendererCommand command)
			{
				if (command is RendererInitResult)
				{
					if (rendererInitialized)
					{
						Log.LogWarning((object)"Renderer recovery detected, reinit interprocess now!");
						PrepareInterprocess();
					}
					else
					{
						rendererInitialized = true;
					}
				}
			}
		}

		[HarmonyPatch]
		public class DynamicVariableBase_Patch
		{
			[HarmonyPatch(typeof(Component), "Initialize")]
			[HarmonyPostfix]
			public static void ParentReferencePostfix(Component __instance)
			{
				//IL_013d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0186: 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_0068: Expected O, but got Unknown
				//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0298: Unknown result type (might be due to invalid IL or missing references)
				//IL_02a2: Expected O, but got Unknown
				//IL_029d: Unknown result type (might be due to invalid IL or missing references)
				global::System.Type type = ((object)__instance).GetType();
				if (type.IsConstructedGenericType && type.GetGenericTypeDefinition() == typeof(DynamicValueVariable<>))
				{
					FieldInfo field = type.GetField("Value", (BindingFlags)20);
					if (!(field == (FieldInfo)null))
					{
						IField val = (IField)field.GetValue((object)__instance);
						FieldInfo handlerField = type.BaseType.GetField("handler", (BindingFlags)36);
						global::System.Type type2 = type.GetGenericArguments()[0];
						MethodInfo dynvarCamSetter = typeof(DynamicVariableBase_Patch).GetMethod("DynvarCamSetter").MakeGenericMethod(new global::System.Type[1] { type2 });
						((IChangeable)val).Changed += delegate
						{
							object value = handlerField.GetValue((object)__instance);
							((MethodBase)dynvarCamSetter).Invoke((object)null, new object[2] { __instance, value });
						};
					}
				}
				else
				{
					if (!(type == typeof(DynamicReferenceVariable<Camera>)))
					{
						return;
					}
					DoDebugLog($"Re:Fract: Found Camera Variable {((Worker)__instance).Name} ({((Worker)__instance).WorkerType} @ {((Worker)__instance).ReferenceID})");
					FieldInfo field2 = type.GetField("Reference", (BindingFlags)20);
					if (field2 == (FieldInfo)null)
					{
						return;
					}
					ISyncRef val2 = (ISyncRef)field2.GetValue((object)__instance);
					DynamicReferenceVariable<Camera> camVar = __instance as DynamicReferenceVariable<Camera>;
					string text = ((SyncField<string>)(object)((DynamicVariableBase<Camera>)(object)camVar)?.VariableName).Value;
					DoDebugLog($"Re:Fract: {((Worker)__instance).Name} ({((Worker)__instance).ReferenceID}) camera name: {text} ");
					((IChangeable)val2).Changed += delegate(IChangeable c)
					{
						//IL_0113: Unknown result type (might be due to invalid IL or missing references)
						string Name = ((SyncField<string>)(object)((DynamicVariableBase<Camera>)(object)camVar)?.VariableName).Value;
						SyncRef<Camera> refVar = c as SyncRef<Camera>;
						Action<IChangeable> handler = null;
						handler = delegate(IChangeable val5)
						{
							//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
							//IL_00c3: Expected O, but got Unknown
							//IL_00be: Unknown result type (might be due to invalid IL or missing references)
							if (val5 is Sync<bool> val4 && refVar != null && refVar.Target != null && camVar != null)
							{
								DoDebugLog($"Re:Fract : Camera \"{Name}\" is {(Sync<bool>.op_Implicit(val4) ? "active" : "inactive")}!");
								if (Sync<bool>.op_Implicit(val4))
								{
									Engine.Current.WorldManager.FocusedWorld.RunInUpdates(2, (Action)delegate
									{
										CameraHelperFunctions.RefreshCameraState(camVar, refVar.Target);
									});
								}
							}
							else if (val5 is Sync<bool> val6)
							{
								DoDebugLog("Re:Fract : Camera \"" + Name + "\" is no longer valid, unsubscribing!");
								((SyncElement)val6).Changed -= handler;
							}
						};
						if (camVar != null && Name != null && Name.StartsWith(DynVarCamKeyString) && refVar != null && refVar.Target != null)
						{
							CameraHelperFunctions.RefreshCameraState(camVar, refVar.Target);
							DoDebugLog("Re:Fract : Camera \"" + Name + "\" updated!");
							_ = ((Component)refVar.Target).Slot.ActiveSelf_Field;
							_ = refVar.Target.Postprocessing;
							EventInfo val3 = typeof(SyncElement).GetEvent("Changed", (BindingFlags)20);
							FieldInfo field3 = typeof(SyncElement).GetField(((MemberInfo)val3).Name, AccessTools.all);
							if (!(field3.GetValue((object)((Component)refVar.Target).Slot.ActiveSelf_Field) is global::System.Delegate source) || !source.HasSubscriber((global::System.Delegate)(object)handler))
							{
								((SyncElement)((Component)refVar.Target).Slot.ActiveSelf_Field).Changed += handler;
								DoDebugLog("Re:Fract : Camera \"" + Name + "\" subscribed to slot active state!");
							}
							if (!(field3.GetValue((object)refVar.Target.Postprocessing) is global::System.Delegate source2) || !source2.HasSubscriber((global::System.Delegate)(object)handler))
							{
								((SyncElement)refVar.Target.Postprocessing).Changed += handler;
								DoDebugLog("Re:Fract : Camera \"" + Name + "\" subscribed to postprocessing state!");
							}
						}
					};
					if (camVar == null || text == null || !text.StartsWith(DynVarCamKeyString))
					{
						return;
					}
					string[] splitName = text.Split('_', (StringSplitOptions)0);
					if (splitName.Length == 3)
					{
						((Worker)__instance).World.RunInUpdates(3, (Action)delegate
						{
							DoDebugLog("Re:Fract : Starting " + splitName[2]);
							CameraHelperFunctions.RefreshCameraState(camVar, camVar.Reference.Target);
							((SyncElement)camVar.Reference).SyncElementChanged((IChangeable)(object)camVar.Reference);
						});
					}
				}
			}

			public static void DynvarCamSetter<T>(DynamicVariableBase<T> __instance, DynamicVariableHandler<T> handler)
			{
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f8: Expected O, but got Unknown
				string text = Sync<string>.op_Implicit(__instance.VariableName);
				if (text == null || !text.StartsWith(DynVarKeyString))
				{
					return;
				}
				T dynamicValue = __instance.DynamicValue;
				if (dynamicValue == null)
				{
					return;
				}
				DynamicVariableSpace currentSpace = handler.CurrentSpace;
				string[] array = text.Split('_', (StringSplitOptions)0);
				if (array.Length == 4)
				{
					string camName = array[1];
					string componentName = array[2];
					string paramName = array[3];
					CameraHelperFunctions.SetCameraVariable(currentSpace, camName, componentName, paramName, dynamicValue);
					return;
				}
				if (array.Length == 3 && array[2] == "RemoveAlpha" && dynamicValue is bool enabled)
				{
					string camName2 = array[1];
					CameraHelperFunctions.SetRemoveAlpha(currentSpace, camName2, enabled);
					return;
				}
				if (array.Length == 2 && array[1] == "RemoveAlpha" && dynamicValue is bool enabled2)
				{
					CameraHelperFunctions.SetRemoveAlphaGlobal(currentSpace, enabled2);
					return;
				}
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(123, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Re:Fract: Unrecognized variable format: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(". Expected Re.Fract_<CamName>_<Component>_<Param> or Re.Fract_<CamName>_RemoveAlpha");
				}
				log.LogWarning(val);
			}
		}

		internal static ManualLogSource Log;

		public static Messenger? _messenger;

		private static bool rendererInitialized;

		[field: CompilerGenerated]
		internal static ReFractConfig BoundConfig
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		public static string DynVarKeyString => "Re.Fract_";

		public static string DynVarCamKeyString => "Re.Fract_Camera_";

		public static string ReFractTag => "Re:FractCameraSpace";

		public override void Load()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			ResoniteHooks.OnEngineReady += new Action(OnEngineReady);
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(26, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("dog.glacier.ReFract");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is binding configs");
			}
			log.LogInfo(val);
			BoundConfig = new ReFractConfig(((BasePlugin)this).Config);
			PrepareInterprocess();
			ManualLogSource log2 = Log;
			val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("dog.glacier.ReFract");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log2.LogInfo(val);
		}

		private static void PrepareInterprocess()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(33, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("dog.glacier.ReFract");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is preparing interprocess");
			}
			log.LogInfo(val);
			Messenger? messenger = _messenger;
			if (messenger != null)
			{
				messenger.Dispose();
			}
			_messenger = new Messenger("dog.glacier.ReFract", true, "dog.glacier.ReFract", (IMemoryPackerEntityPool)null, 1048576L);
			BepInExExtensions.SyncConfigEntry<bool>(_messenger, BoundConfig.debugLogging);
			BepInExExtensions.SyncConfigEntry<bool>(_messenger, BoundConfig.forceRemoveAlpha);
			BepInExExtensions.SyncConfigEntry<bool>(_messenger, BoundConfig.ignoreTransparencyOnBlit);
		}

		private void OnEngineReady()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			try
			{
				new Harmony("dog.glacier.ReFract").PatchAll();
				Engine.Current.OnShutdownRequest += delegate
				{
					//IL_000a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0010: Expected O, but got Unknown
					ManualLogSource log2 = Log;
					bool flag2 = default(bool);
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(37, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Plugin ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("dog.glacier.ReFract");
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" is shutting down interprocess");
					}
					log2.LogInfo(val2);
					Messenger? messenger = _messenger;
					if (messenger != null)
					{
						messenger.Dispose();
					}
				};
				Log.LogInfo((object)"Re:Fract is fully loaded!");
			}
			catch (global::System.Exception ex)
			{
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(26, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Re:Fract failed to patch: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<global::System.Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static void DoDebugLog(string input)
		{
			if (BoundConfig.debugLogging.Value)
			{
				Log.LogDebug((object)input);
			}
		}
	}
	public static class PluginMetadata
	{
		public const string GUID = "dog.glacier.ReFract";

		public const string NAME = "Re:Fract // Reloaded";

		public const string VERSION = "1.1.0";

		public const string AUTHORS = "Noble, yosh, pocoworks, Cyro";

		public const string REPOSITORY_URL = "https://github.com/noblereign/ReFract-ReLoaded";
	}
}
namespace ReFract.Shared
{
	public enum ReFractCommandValueType : byte
	{
		Int,
		Float,
		Bool,
		Color,
		Vector2,
		Vector4,
		String
	}
	public struct ReFractColor
	{
		public float r;

		public float g;

		public float b;

		public float a;

		public string ToString()
		{
			return $"({r}, {g}, {b}, {a})";
		}
	}
	public struct ReFractVector2
	{
		public float x;

		public float y;

		public string ToString()
		{
			return $"({x}, {y})";
		}
	}
	public struct ReFractVector4
	{
		public float x;

		public float y;

		public float z;

		public float w;

		public string ToString()
		{
			return $"({x}, {y}, {z}, {w})";
		}
	}
	public class ReFractCommand : RendererCommand
	{
		public int RenderTextureId;

		public bool IsRemoveAlphaCommand;

		public string CameraName = "";

		public string ComponentName = "";

		public string ParameterName = "";

		public ReFractCommandValueType ValueType;

		public int IntValue;

		public float FloatValue;

		public bool BoolValue;

		public ReFractColor ColorValue;

		public ReFractVector2 Vector2Value;

		public ReFractVector4 Vector4Value;

		public string StringValue = "";

		public override void Pack(ref MemoryPacker packer)
		{
			((MemoryPacker)(ref packer)).Write<int>(RenderTextureId);
			((MemoryPacker)(ref packer)).Write<bool>(IsRemoveAlphaCommand);
			((MemoryPacker)(ref packer)).Write(CameraName);
			((MemoryPacker)(ref packer)).Write(ComponentName);
			((MemoryPacker)(ref packer)).Write(ParameterName);
			((MemoryPacker)(ref packer)).Write<byte>((byte)ValueType);
			switch (ValueType)
			{
			case ReFractCommandValueType.Int:
				((MemoryPacker)(ref packer)).Write<int>(IntValue);
				break;
			case ReFractCommandValueType.Float:
				((MemoryPacker)(ref packer)).Write<float>(FloatValue);
				break;
			case ReFractCommandValueType.Bool:
				((MemoryPacker)(ref packer)).Write<bool>(BoolValue);
				break;
			case ReFractCommandValueType.Color:
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.r);
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.g);
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.b);
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.a);
				break;
			case ReFractCommandValueType.Vector2:
				((MemoryPacker)(ref packer)).Write<float>(Vector2Value.x);
				((MemoryPacker)(ref packer)).Write<float>(Vector2Value.y);
				break;
			case ReFractCommandValueType.Vector4:
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.x);
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.y);
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.z);
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.w);
				break;
			case ReFractCommandValueType.String:
				((MemoryPacker)(ref packer)).Write(StringValue);
				break;
			}
		}

		public override void Unpack(ref MemoryUnpacker unpacker)
		{
			((MemoryUnpacker)(ref unpacker)).Read<int>(ref RenderTextureId);
			((MemoryUnpacker)(ref unpacker)).Read<bool>(ref IsRemoveAlphaCommand);
			((MemoryUnpacker)(ref unpacker)).Read(ref CameraName);
			((MemoryUnpacker)(ref unpacker)).Read(ref ComponentName);
			((MemoryUnpacker)(ref unpacker)).Read(ref ParameterName);
			((MemoryUnpacker)(ref unpacker)).Read<ReFractCommandValueType>(ref ValueType);
			switch (ValueType)
			{
			case ReFractCommandValueType.Int:
				((MemoryUnpacker)(ref unpacker)).Read<int>(ref IntValue);
				break;
			case ReFractCommandValueType.Float:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref FloatValue);
				break;
			case ReFractCommandValueType.Bool:
				((MemoryUnpacker)(ref unpacker)).Read<bool>(ref BoolValue);
				break;
			case ReFractCommandValueType.Color:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.r);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.g);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.b);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.a);
				break;
			case ReFractCommandValueType.Vector2:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector2Value.x);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector2Value.y);
				break;
			case ReFractCommandValueType.Vector4:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.x);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.y);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.z);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.w);
				break;
			case ReFractCommandValueType.String:
				((MemoryUnpacker)(ref unpacker)).Read(ref StringValue);
				break;
			}
		}
	}
	internal class ReFractConfig
	{
		public readonly ConfigEntry<bool> debugLogging;

		public readonly ConfigEntry<bool> forceRemoveAlpha;

		public readonly ConfigEntry<bool> ignoreTransparencyOnBlit;

		public ReFractConfig(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			debugLogging = cfg.Bind<bool>("General", "Debug logging", false, "Whether or not to print debug logging. This can make your log files grow incredibly quickly, only enable it if you really need it");
			forceRemoveAlpha = cfg.Bind<bool>("General", "Always reset alpha channel", false, "By default, Re:Fract embeds the depth data of photos in the alpha channel. If you're using a camera without the option to disable that behavior, you can force it to happen here.");
			ignoreTransparencyOnBlit = cfg.Bind<bool>("General", "Ignore alpha when mirroring display", false, "Uses a different shader that ignores transparency for the 'Mirror to Display' option on the Streaming Camera.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			((Dictionary<ConfigDefinition, string>)AccessTools.Property(typeof(ConfigFile), "OrphanedEntries").GetValue((object)cfg)).Clear();
		}
	}
	public class RestartCommand : IMemoryPackable
	{
		public void Pack(ref MemoryPacker packer)
		{
		}

		public void Unpack(ref MemoryUnpacker unpacker)
		{
		}
	}
}

Renderer/BepInEx/plugins/ReFract.Unity/ReFract_Unity.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AmplifyOcclusion;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using InterprocessLib;
using Microsoft.CodeAnalysis;
using ReFract.Shared;
using Renderite.Shared;
using Renderite.Unity;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Noble")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+53860b674ee7122ede15f66d63210c4a0006cffb")]
[assembly: AssemblyProduct("Re:Fract // Reloaded (for Unity)")]
[assembly: AssemblyTitle("ReFract_Unity")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/noblereign/ReFract-ReLoaded")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ReFract.Shared
{
	public enum ReFractCommandValueType : byte
	{
		Int,
		Float,
		Bool,
		Color,
		Vector2,
		Vector4,
		String
	}
	public struct ReFractColor
	{
		public float r;

		public float g;

		public float b;

		public float a;

		public override string ToString()
		{
			return $"({r}, {g}, {b}, {a})";
		}
	}
	public struct ReFractVector2
	{
		public float x;

		public float y;

		public override string ToString()
		{
			return $"({x}, {y})";
		}
	}
	public struct ReFractVector4
	{
		public float x;

		public float y;

		public float z;

		public float w;

		public override string ToString()
		{
			return $"({x}, {y}, {z}, {w})";
		}
	}
	public class ReFractCommand : RendererCommand
	{
		public int RenderTextureId;

		public bool IsRemoveAlphaCommand;

		public string CameraName = "";

		public string ComponentName = "";

		public string ParameterName = "";

		public ReFractCommandValueType ValueType;

		public int IntValue;

		public float FloatValue;

		public bool BoolValue;

		public ReFractColor ColorValue;

		public ReFractVector2 Vector2Value;

		public ReFractVector4 Vector4Value;

		public string StringValue = "";

		public override void Pack(ref MemoryPacker packer)
		{
			((MemoryPacker)(ref packer)).Write<int>(RenderTextureId);
			((MemoryPacker)(ref packer)).Write<bool>(IsRemoveAlphaCommand);
			((MemoryPacker)(ref packer)).Write(CameraName);
			((MemoryPacker)(ref packer)).Write(ComponentName);
			((MemoryPacker)(ref packer)).Write(ParameterName);
			((MemoryPacker)(ref packer)).Write<byte>((byte)ValueType);
			switch (ValueType)
			{
			case ReFractCommandValueType.Int:
				((MemoryPacker)(ref packer)).Write<int>(IntValue);
				break;
			case ReFractCommandValueType.Float:
				((MemoryPacker)(ref packer)).Write<float>(FloatValue);
				break;
			case ReFractCommandValueType.Bool:
				((MemoryPacker)(ref packer)).Write<bool>(BoolValue);
				break;
			case ReFractCommandValueType.Color:
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.r);
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.g);
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.b);
				((MemoryPacker)(ref packer)).Write<float>(ColorValue.a);
				break;
			case ReFractCommandValueType.Vector2:
				((MemoryPacker)(ref packer)).Write<float>(Vector2Value.x);
				((MemoryPacker)(ref packer)).Write<float>(Vector2Value.y);
				break;
			case ReFractCommandValueType.Vector4:
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.x);
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.y);
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.z);
				((MemoryPacker)(ref packer)).Write<float>(Vector4Value.w);
				break;
			case ReFractCommandValueType.String:
				((MemoryPacker)(ref packer)).Write(StringValue);
				break;
			}
		}

		public override void Unpack(ref MemoryUnpacker unpacker)
		{
			((MemoryUnpacker)(ref unpacker)).Read<int>(ref RenderTextureId);
			((MemoryUnpacker)(ref unpacker)).Read<bool>(ref IsRemoveAlphaCommand);
			((MemoryUnpacker)(ref unpacker)).Read(ref CameraName);
			((MemoryUnpacker)(ref unpacker)).Read(ref ComponentName);
			((MemoryUnpacker)(ref unpacker)).Read(ref ParameterName);
			((MemoryUnpacker)(ref unpacker)).Read<ReFractCommandValueType>(ref ValueType);
			switch (ValueType)
			{
			case ReFractCommandValueType.Int:
				((MemoryUnpacker)(ref unpacker)).Read<int>(ref IntValue);
				break;
			case ReFractCommandValueType.Float:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref FloatValue);
				break;
			case ReFractCommandValueType.Bool:
				((MemoryUnpacker)(ref unpacker)).Read<bool>(ref BoolValue);
				break;
			case ReFractCommandValueType.Color:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.r);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.g);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.b);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref ColorValue.a);
				break;
			case ReFractCommandValueType.Vector2:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector2Value.x);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector2Value.y);
				break;
			case ReFractCommandValueType.Vector4:
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.x);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.y);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.z);
				((MemoryUnpacker)(ref unpacker)).Read<float>(ref Vector4Value.w);
				break;
			case ReFractCommandValueType.String:
				((MemoryUnpacker)(ref unpacker)).Read(ref StringValue);
				break;
			}
		}
	}
	internal class ReFractConfig
	{
		public readonly ConfigEntry<bool> debugLogging;

		public readonly ConfigEntry<bool> forceRemoveAlpha;

		public readonly ConfigEntry<bool> ignoreTransparencyOnBlit;

		public ReFractConfig(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			debugLogging = cfg.Bind<bool>("General", "Debug logging", false, "Whether or not to print debug logging. This can make your log files grow incredibly quickly, only enable it if you really need it");
			forceRemoveAlpha = cfg.Bind<bool>("General", "Always reset alpha channel", false, "By default, Re:Fract embeds the depth data of photos in the alpha channel. If you're using a camera without the option to disable that behavior, you can force it to happen here.");
			ignoreTransparencyOnBlit = cfg.Bind<bool>("General", "Ignore alpha when mirroring display", false, "Uses a different shader that ignores transparency for the 'Mirror to Display' option on the Streaming Camera.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			((Dictionary<ConfigDefinition, string>)AccessTools.Property(typeof(ConfigFile), "OrphanedEntries").GetValue(cfg)).Clear();
		}
	}
	public class RestartCommand : IMemoryPackable
	{
		public void Pack(ref MemoryPacker packer)
		{
		}

		public void Unpack(ref MemoryUnpacker unpacker)
		{
		}
	}
}
namespace ReFract.Unity
{
	public static class Introspection
	{
		public delegate void RefAction<T1, T2>(ref T1 obj, T2 value);

		public static Dictionary<Type, Dictionary<string, RefAction<object, object>>> _cachedSetters = new Dictionary<Type, Dictionary<string, RefAction<object, object>>>();

		public static Dictionary<Type, Dictionary<string, Action<object, object>>> _cachedPropSetters = new Dictionary<Type, Dictionary<string, Action<object, object>>>();

		private static void DoDebugLog(string input)
		{
			if (Plugin.BoundConfig.debugLogging.Value)
			{
				Debug.Log((object)input);
			}
		}

		public static RefAction<object, object>? GetFieldSetter(Type obj, string fieldName, Func<Type, FieldInfo, ILGenerator, bool>? ilOverride = null)
		{
			try
			{
				return _cachedSetters[obj][fieldName];
			}
			catch
			{
				if (obj == null || fieldName == null || fieldName.Length == 0)
				{
					return null;
				}
				DoDebugLog("Introspection : Getting field");
				FieldInfo field = obj.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				DoDebugLog("Introspection : Field is " + ((field == null) ? "null" : "not null"));
				if (field == null)
				{
					return null;
				}
				DoDebugLog("Introspection : Field is " + field.Name);
				RefAction<object, object> dynamicMethod = GetDynamicMethod(obj, field, ilOverride);
				DoDebugLog("Introspection : Delegate is " + ((dynamicMethod == null) ? "null" : ("not null & " + dynamicMethod.GetType().ToString())));
				if (dynamicMethod == null)
				{
					return null;
				}
				if (!_cachedSetters.ContainsKey(obj))
				{
					_cachedSetters.Add(obj, new Dictionary<string, RefAction<object, object>>());
				}
				_cachedSetters[obj].Add(fieldName, dynamicMethod);
				DoDebugLog("Introspection : Added delegate to dictionary at " + obj.ToString() + "." + fieldName);
				return dynamicMethod;
			}
		}

		public static Action<object, object>? GetPropSetter(Type obj, string propName)
		{
			try
			{
				return _cachedPropSetters[obj][propName];
			}
			catch
			{
				if (obj == null || propName == null || propName.Length == 0)
				{
					return null;
				}
				DoDebugLog("Introspection : Getting property of " + obj.ToString() + " with name " + propName);
				PropertyInfo property = obj.GetProperty(propName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				DoDebugLog("Introspection : Property is " + ((property == null) ? "null" : "not null"));
				if (property == null)
				{
					return null;
				}
				DoDebugLog("Introspection : Property is " + property.Name);
				Action<object, object> dynamicPropMethod = GetDynamicPropMethod(obj, property);
				DoDebugLog("Introspection : Delegate is " + ((dynamicPropMethod == null) ? "null" : ("not null & " + dynamicPropMethod.GetType().ToString())));
				if (dynamicPropMethod == null)
				{
					return null;
				}
				if (!_cachedPropSetters.ContainsKey(obj))
				{
					_cachedPropSetters.Add(obj, new Dictionary<string, Action<object, object>>());
				}
				_cachedPropSetters[obj].Add(propName, dynamicPropMethod);
				DoDebugLog("Introspection : Added delegate to dictionary at " + obj.ToString() + "." + propName);
				return dynamicPropMethod;
			}
		}

		public static RefAction<object, object> GetDynamicMethod(Type obj, FieldInfo field, Func<Type, FieldInfo, ILGenerator, bool>? ilOverride = null)
		{
			DynamicMethod dynamicMethod = new DynamicMethod("", null, new Type[2]
			{
				typeof(object).MakeByRefType(),
				typeof(object)
			}, restrictedSkipVisibility: true);
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator(256);
			Label label = iLGenerator.DefineLabel();
			iLGenerator.DefineLabel();
			Label label2 = iLGenerator.DefineLabel();
			Label label3 = iLGenerator.DefineLabel();
			if (ilOverride == null || !ilOverride(obj, field, iLGenerator))
			{
				iLGenerator.Emit(OpCodes.Ldarg_1);
				iLGenerator.Emit(OpCodes.Callvirt, typeof(object).GetMethod("GetType"));
				iLGenerator.Emit(OpCodes.Ldtoken, typeof(int));
				iLGenerator.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
				iLGenerator.Emit(OpCodes.Ceq);
				iLGenerator.Emit(OpCodes.Brfalse, label2);
				iLGenerator.Emit(OpCodes.Ldtoken, field.FieldType);
				iLGenerator.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
				iLGenerator.Emit(OpCodes.Call, typeof(Type).GetProperty("IsEnum").GetGetMethod());
				iLGenerator.Emit(OpCodes.Brtrue, label3);
				iLGenerator.MarkLabel(label2);
				iLGenerator.Emit(OpCodes.Ldarg_1);
				iLGenerator.Emit(OpCodes.Callvirt, typeof(object).GetMethod("GetType"));
				iLGenerator.Emit(OpCodes.Ldtoken, field.FieldType);
				iLGenerator.Emit(OpCodes.Call, typeof(Type).GetMethod("GetTypeFromHandle"));
				iLGenerator.Emit(OpCodes.Ceq);
				iLGenerator.Emit(OpCodes.Brfalse, label);
				iLGenerator.MarkLabel(label3);
				iLGenerator.Emit(OpCodes.Ldarg_0);
				iLGenerator.Emit(OpCodes.Ldind_Ref);
				iLGenerator.Emit(OpCodes.Castclass, obj);
				iLGenerator.Emit(OpCodes.Ldarg_1);
				iLGenerator.Emit(OpCodes.Unbox_Any, field.FieldType);
				iLGenerator.Emit(OpCodes.Stfld, field);
				iLGenerator.Emit(OpCodes.Ret);
				iLGenerator.MarkLabel(label);
				iLGenerator.Emit(OpCodes.Ldstr, $"[Re:Fract] Introspection : Wrong type for field \"{field.Name}\" which takes \"{field.FieldType}\"");
				iLGenerator.Emit(OpCodes.Call, typeof(Debug).GetMethod("LogWarning", new Type[1] { typeof(string) }));
				iLGenerator.Emit(OpCodes.Ret);
				DoDebugLog("Introspection : Generated dynamic method with default IL");
			}
			DoDebugLog("Introspection : Creation of DynamicMethod was successful for " + obj.ToString() + "." + field.Name);
			return (RefAction<object, object>)dynamicMethod.CreateDelegate(typeof(RefAction<, >).MakeGenericType(typeof(object), typeof(object)));
		}

		public static Action<object, object>? GetDynamicPropMethod(Type obj, PropertyInfo prop)
		{
			if (obj == null || prop == null || !prop.CanWrite)
			{
				return null;
			}
			MethodInfo setMethod = prop.GetSetMethod(nonPublic: true);
			if (setMethod == null)
			{
				return null;
			}
			DynamicMethod dynamicMethod = new DynamicMethod("", null, new Type[2]
			{
				typeof(object),
				typeof(object)
			}, restrictedSkipVisibility: true);
			ILGenerator iLGenerator = dynamicMethod.GetILGenerator(256);
			iLGenerator.Emit(OpCodes.Ldarg_0);
			iLGenerator.Emit(OpCodes.Castclass, obj);
			iLGenerator.Emit(OpCodes.Ldarg_1);
			iLGenerator.Emit(OpCodes.Unbox_Any, prop.PropertyType);
			iLGenerator.Emit(OpCodes.Call, setMethod);
			iLGenerator.Emit(OpCodes.Ret);
			DoDebugLog("Introspection : Created delegate for property " + prop.Name);
			return (Action<object, object>)dynamicMethod.CreateDelegate(typeof(Action<object, object>));
		}
	}
	public class ReFractVolumeTracker : MonoBehaviour
	{
		public GameObject VolumeObject;

		private void OnDestroy()
		{
			if ((Object)(object)VolumeObject != (Object)null)
			{
				Object.Destroy((Object)(object)VolumeObject);
				return;
			}
			Transform val = ((Component)this).transform.Find("ReFract_Volume");
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
		}
	}
	[BepInPlugin("dog.glacier.ReFractUnity", "Re:Fract // Reloaded (for Unity)", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		public static class TextureDisplayBlitter_Blit_Patch
		{
			private static readonly List<WeakReference<Material>> _trackedMaterials = new List<WeakReference<Material>>();

			public static void UpdateAllMaterials()
			{
				bool value = BoundConfig.ignoreTransparencyOnBlit.Value;
				Shader val = Shader.Find(value ? "Unlit/Texture" : "Unlit/Transparent");
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				for (int num = _trackedMaterials.Count - 1; num >= 0; num--)
				{
					if (_trackedMaterials[num].TryGetTarget(out Material target) && (Object)(object)target != (Object)null)
					{
						target.shader = val;
					}
					else
					{
						_trackedMaterials.RemoveAt(num);
					}
				}
				Debug.Log((object)string.Format("[Re:Fract] Updated {0} active displays to {1}", _trackedMaterials.Count, value ? "Opaque" : "Transparent"));
			}

			public static Material CreateTrackedMaterial(Shader originalShader)
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				Material val = new Material((Shader)(BoundConfig.ignoreTransparencyOnBlit.Value ? ((object)Shader.Find("Unlit/Texture")) : ((object)originalShader)));
				_trackedMaterials.Add(new WeakReference<Material>(val));
				return val;
			}

			[HarmonyTranspiler]
			public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				ConstructorInfo matConstructor = AccessTools.Constructor(typeof(Material), new Type[1] { typeof(Shader) }, false);
				MethodInfo replacementMethod = AccessTools.Method(typeof(TextureDisplayBlitter_Blit_Patch), "CreateTrackedMaterial", (Type[])null, (Type[])null);
				bool patched = false;
				foreach (CodeInstruction instruction in instructions)
				{
					if (!patched && instruction.opcode == OpCodes.Newobj && instruction.operand is MethodBase methodBase && methodBase == matConstructor)
					{
						instruction.opcode = OpCodes.Call;
						instruction.operand = replacementMethod;
						patched = true;
					}
					yield return instruction;
				}
				if (!patched)
				{
					Debug.LogError((object)"[Re:Fract] Transpiler failed to find Material constructor in Blit, display mirror option will be ignored");
				}
			}
		}

		[HarmonyPatch(typeof(CameraRenderer), "Render")]
		public static class CameraRenderer_Patch
		{
			private static FieldInfo _cameraField;

			private static FieldInfo _camera360Field;

			private static Camera FindSourceCamera(CameraRenderTask task)
			{
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_0103: Invalid comparison between Unknown and I4
				//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Invalid comparison between Unknown and I4
				//IL_013d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0142: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: 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)
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(task.position.x, task.position.y, task.position.z);
				Quaternion val2 = default(Quaternion);
				((Quaternion)(ref val2))..ctor(task.rotation.x, task.rotation.y, task.rotation.z, task.rotation.w);
				Camera result = null;
				float num = float.MaxValue;
				foreach (List<Camera> value in _cameraCache.Values)
				{
					if (value == null)
					{
						continue;
					}
					foreach (Camera item in value)
					{
						if ((Object)(object)item == (Object)null || !((Behaviour)item).isActiveAndEnabled)
						{
							continue;
						}
						if (item.orthographic)
						{
							if ((int)task.parameters.projection != 1 || Mathf.Abs(item.orthographicSize - task.parameters.orthographicSize) > 0.01f)
							{
								continue;
							}
						}
						else if ((int)task.parameters.projection == 1 || (task.parameters.fov < 180f && Mathf.Abs(item.fieldOfView - task.parameters.fov) > 5f))
						{
							continue;
						}
						float num2 = Vector3.Distance(((Component)item).transform.position, val);
						float num3 = Quaternion.Angle(((Component)item).transform.rotation, val2);
						if (num2 < 2f && num3 < 15f && num2 < num)
						{
							num = num2;
							result = item;
						}
					}
				}
				return result;
			}

			private static Camera GetCaptureCamera(CameraRenderTask task)
			{
				if (task.parameters.fov >= 180f)
				{
					if (_camera360Field == null)
					{
						_camera360Field = AccessTools.Field(typeof(CameraRenderer), "camera360");
					}
					object value = _camera360Field.GetValue(null);
					if (value == null)
					{
						return null;
					}
					object? obj = AccessTools.Property(value.GetType(), "Camera")?.GetValue(value);
					return (Camera)((obj is Camera) ? obj : null);
				}
				if (_cameraField == null)
				{
					_cameraField = AccessTools.Field(typeof(CameraRenderer), "camera");
				}
				object? value2 = _cameraField.GetValue(null);
				return (Camera)((value2 is Camera) ? value2 : null);
			}

			private static void SetAmplifyOcclusionDefaults(AmplifyOcclusionEffect amplifyOcclusion)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
				amplifyOcclusion.ApplyMethod = (ApplicationMethod)0;
				amplifyOcclusion.SampleCount = (SampleCountLevel)0;
				amplifyOcclusion.PerPixelNormals = (PerPixelNormalSource)0;
				amplifyOcclusion.Intensity = 1f;
				amplifyOcclusion.Tint = new Color(0f, 0f, 0f, 1f);
				amplifyOcclusion.Radius = 4f;
				amplifyOcclusion.PowerExponent = 0.6f;
				amplifyOcclusion.Bias = 0.05f;
				amplifyOcclusion.Thickness = 1f;
				amplifyOcclusion.Downsample = true;
				amplifyOcclusion.CacheAware = true;
				amplifyOcclusion.BlurEnabled = true;
				amplifyOcclusion.BlurRadius = 4;
				amplifyOcclusion.BlurPasses = 4;
				amplifyOcclusion.BlurSharpness = 3f;
				amplifyOcclusion.FadeEnabled = true;
				amplifyOcclusion.FadeStart = 16f;
				amplifyOcclusion.FadeLength = 128f;
				amplifyOcclusion.FadeToIntensity = 0f;
				amplifyOcclusion.FadeToRadius = 2f;
				amplifyOcclusion.FadeToThickness = 1f;
				amplifyOcclusion.FadeToTint = new Color(0f, 0f, 0f, 1f);
				amplifyOcclusion.FadeToPowerExponent = 1f;
				amplifyOcclusion.FilterEnabled = false;
				amplifyOcclusion.FilterDownsample = true;
				amplifyOcclusion.FilterBlending = 0.8f;
				amplifyOcclusion.FilterResponse = 0.5f;
				amplifyOcclusion.useMRTBlendingFallback = false;
			}

			[HarmonyPrefix]
			public static void Prefix(CameraRenderTask task, out Camera __state)
			{
				//IL_0216: Unknown result type (might be due to invalid IL or missing references)
				//IL_021b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0223: Unknown result type (might be due to invalid IL or missing references)
				//IL_0228: Unknown result type (might be due to invalid IL or missing references)
				//IL_0230: Unknown result type (might be due to invalid IL or missing references)
				//IL_0235: Unknown result type (might be due to invalid IL or missing references)
				//IL_024a: Unknown result type (might be due to invalid IL or missing references)
				//IL_024f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0327: Unknown result type (might be due to invalid IL or missing references)
				//IL_032c: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_0114: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: 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_01b4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
				__state = null;
				Camera captureCamera = GetCaptureCamera(task);
				if ((Object)(object)captureCamera == (Object)null)
				{
					return;
				}
				AmplifyOcclusionEffect component = ((Component)captureCamera).GetComponent<AmplifyOcclusionEffect>();
				Camera val = (__state = FindSourceCamera(task));
				PostProcessVolume component2 = ((Component)captureCamera).gameObject.GetComponent<PostProcessVolume>();
				Transform val2 = ((Component)captureCamera).transform.Find("ReFract_Volume");
				PostProcessVolume val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponent<PostProcessVolume>() : null);
				if ((Object)(object)val != (Object)null)
				{
					Debug.Log((object)$"[Re:Fract] Syncing PostProcess from '{((Object)val).GetInstanceID()}' to Capture Camera.");
					lastCameraPair.Capture.SetTarget(captureCamera);
					lastCameraPair.Source.SetTarget(val);
					PostProcessVolume componentInChildren = ((Component)val).GetComponentInChildren<PostProcessVolume>();
					if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.profile != (Object)null)
					{
						int num = LayerMask.NameToLayer("Ignore Raycast");
						if ((Object)(object)val3 == (Object)null)
						{
							GameObject val4 = new GameObject("ReFract_Volume");
							val4.transform.SetParent(((Component)captureCamera).transform, false);
							val4.layer = num;
							val3 = val4.AddComponent<PostProcessVolume>();
							BoxCollider obj = val4.AddComponent<BoxCollider>();
							((Collider)obj).isTrigger = true;
							obj.size = Vector3.one * 0.01f;
							val3.isGlobal = false;
						}
						if ((Object)(object)component2 != (Object)null)
						{
							((Behaviour)component2).enabled = false;
						}
						((Behaviour)val3).enabled = true;
						PostProcessProfile val5 = Object.Instantiate<PostProcessProfile>(componentInChildren.profile);
						MotionBlur setting = val5.GetSetting<MotionBlur>();
						if ((Object)(object)setting != (Object)null)
						{
							((ParameterOverride<bool>)(object)((PostProcessEffectSettings)setting).enabled).value = false;
						}
						val3.profile = val5;
						val3.weight = componentInChildren.weight;
						PostProcessLayer component3 = ((Component)captureCamera).GetComponent<PostProcessLayer>();
						if ((Object)(object)component3 != (Object)null)
						{
							component3.volumeLayer = LayerMask.op_Implicit(LayerMask.op_Implicit(component3.volumeLayer) | (1 << num));
							component3.volumeTrigger = ((Component)captureCamera).transform;
						}
					}
					AmplifyOcclusionEffect component4 = ((Component)val).GetComponent<AmplifyOcclusionEffect>();
					if ((Object)(object)component != (Object)null)
					{
						if ((Object)(object)component4 != (Object)null)
						{
							Debug.Log((object)$"[Re:Fract] Syncing Amplify Occlusion from '{((Object)val).GetInstanceID()}' to Capture Camera.");
							((Behaviour)component).enabled = ((Behaviour)component4).enabled;
							component.ApplyMethod = component4.ApplyMethod;
							component.SampleCount = component4.SampleCount;
							component.PerPixelNormals = component4.PerPixelNormals;
							component.Intensity = component4.Intensity;
							component.Tint = component4.Tint;
							component.Radius = component4.Radius;
							component.PowerExponent = component4.PowerExponent;
							component.Bias = component4.Bias;
							component.Thickness = component4.Thickness;
							component.Downsample = component4.Downsample;
							component.CacheAware = component4.CacheAware;
							component.BlurEnabled = component4.BlurEnabled;
							component.BlurRadius = component4.BlurRadius;
							component.BlurPasses = component4.BlurPasses;
							component.BlurSharpness = component4.BlurSharpness;
							component.FadeEnabled = component4.FadeEnabled;
							component.FadeStart = component4.FadeStart;
							component.FadeLength = component4.FadeLength;
							component.FadeToIntensity = component4.FadeToIntensity;
							component.FadeToRadius = component4.FadeToRadius;
							component.FadeToThickness = component4.FadeToThickness;
							component.FadeToTint = component4.FadeToTint;
							component.FadeToPowerExponent = component4.FadeToPowerExponent;
							component.FilterEnabled = component4.FilterEnabled;
							component.FilterDownsample = component4.FilterDownsample;
							component.FilterBlending = component4.FilterBlending;
							component.FilterResponse = component4.FilterResponse;
							component.useMRTBlendingFallback = component4.useMRTBlendingFallback;
						}
						else
						{
							SetAmplifyOcclusionDefaults(component);
						}
					}
				}
				else
				{
					if ((Object)(object)component2 != (Object)null)
					{
						((Behaviour)component2).enabled = false;
					}
					if ((Object)(object)val3 != (Object)null)
					{
						((Behaviour)val3).enabled = false;
					}
					if ((Object)(object)component != (Object)null)
					{
						SetAmplifyOcclusionDefaults(component);
					}
				}
			}

			[HarmonyPostfix]
			public static void Postfix(CameraRenderTask task, Camera __state)
			{
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)__state == (Object)null || (Object)(object)__state.targetTexture == (Object)null || (!(_removeAlphaCameras.TryGetValue(((Object)__state.targetTexture).GetInstanceID(), out var value) && value) && !BoundConfig.forceRemoveAlpha.Value))
				{
					return;
				}
				try
				{
					Span<byte> span = RenderingManager.Instance.SharedMemory.AccessData<byte>(task.resultData);
					int num = 3;
					if (((object)Unsafe.As<TextureFormat, TextureFormat>(ref task.parameters.textureFormat)/*cast due to .constrained prefix*/).ToString().IndexOf("ARGB", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						num = 0;
					}
					for (int i = num; i < span.Length; i += 4)
					{
						span[i] = byte.MaxValue;
					}
				}
				catch (Exception arg)
				{
					Debug.LogError((object)$"[Re:Fract] Failed to remove alpha: {arg}");
				}
			}
		}

		[HarmonyPatch(typeof(CameraPostprocessingManager), "UpdatePostProcessing", new Type[]
		{
			typeof(bool),
			typeof(bool),
			typeof(bool)
		})]
		public static class CameraPostProcessingManager_UpdatePostProcessing_Patch
		{
			[HarmonyPostfix]
			public static void Postfix(CameraPostprocessingManager __instance, bool enabled, bool motionBlur, bool screenspaceReflections)
			{
				lastCameraPair.Capture.TryGetTarget(out Camera target);
				lastCameraPair.Source.TryGetTarget(out Camera target2);
				lastCameraPair.Capture.SetTarget(null);
				lastCameraPair.Source.SetTarget(null);
				if ((Object)(object)__instance.Camera != (Object)null && (Object)(object)__instance.Camera == (Object)(object)target && (Object)(object)target != (Object)null && (Object)(object)target2 != (Object)null && !((Object)(object)__instance._postProcessing == (Object)null) && (Object)(object)__instance._ao != (Object)null)
				{
					AmplifyOcclusionEffect component = ((Component)target2).GetComponent<AmplifyOcclusionEffect>();
					if ((Object)(object)component != (Object)null)
					{
						((Behaviour)__instance._ao).enabled = ((Behaviour)component).enabled;
						return;
					}
					Debug.LogWarning((object)"[Re:Fract] Could not find the source camera's AO, so we'll set it like the vanilla game");
					((Behaviour)__instance._ao).enabled = enabled;
				}
			}
		}

		private Messenger _msg;

		private static readonly Dictionary<int, List<Camera>> _cameraCache = new Dictionary<int, List<Camera>>();

		private static readonly Dictionary<int, bool> _removeAlphaCameras = new Dictionary<int, bool>();

		private readonly ConcurrentQueue<Action> _mainThreadQueue = new ConcurrentQueue<Action>();

		public static Dictionary<string, Type> TypeLookups = new Dictionary<string, Type>
		{
			{
				"AmbientOcclusion",
				typeof(AmbientOcclusion)
			},
			{
				"AutoExposure",
				typeof(AutoExposure)
			},
			{
				"Bloom",
				typeof(Bloom)
			},
			{
				"ChromaticAberration",
				typeof(ChromaticAberration)
			},
			{
				"ColorGrading",
				typeof(ColorGrading)
			},
			{
				"DepthOfField",
				typeof(DepthOfField)
			},
			{
				"Grain",
				typeof(Grain)
			},
			{
				"LensDistortion",
				typeof(LensDistortion)
			},
			{
				"MotionBlur",
				typeof(MotionBlur)
			},
			{
				"ScreenSpaceReflections",
				typeof(ScreenSpaceReflections)
			},
			{
				"Vignette",
				typeof(Vignette)
			},
			{
				"AmplifyOcclusionBase",
				typeof(AmplifyOcclusionEffect)
			},
			{
				"AmplifyOcclusionEffect",
				typeof(AmplifyOcclusionEffect)
			}
		};

		private static (WeakReference<Camera> Capture, WeakReference<Camera> Source) lastCameraPair = (Capture: new WeakReference<Camera>(null), Source: new WeakReference<Camera>(null));

		internal static ReFractConfig BoundConfig { get; private set; } = null;

		private void Awake()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)"[Re:Fract] Binding configs");
			BoundConfig = new ReFractConfig(((BaseUnityPlugin)this).Config);
			Debug.Log((object)"[Re:Fract] Setting up interprocess");
			_msg = new Messenger("dog.glacier.ReFract", false, "dog.glacier.ReFract", (IMemoryPackerEntityPool)null, 1048576L);
			_msg.ReceiveObject<ReFractCommand>("SetVariable", (Action<ReFractCommand>)HandleSetVariable);
			BepInExExtensions.SyncConfigEntry<bool>(_msg, BoundConfig.debugLogging);
			BepInExExtensions.SyncConfigEntry<bool>(_msg, BoundConfig.forceRemoveAlpha);
			BepInExExtensions.SyncConfigEntry<bool>(_msg, BoundConfig.ignoreTransparencyOnBlit);
			Application.quitting += delegate
			{
				Debug.Log((object)"[Re:Fract] Shutting down interprocess!");
				_msg.Dispose();
			};
			BoundConfig.ignoreTransparencyOnBlit.SettingChanged += delegate
			{
				_mainThreadQueue.Enqueue(delegate
				{
					TextureDisplayBlitter_Blit_Patch.UpdateAllMaterials();
				});
			};
			Debug.Log((object)"[Re:Fract] Running harmony patches!");
			new Harmony("dog.glacier.ReFractUnity").PatchAll();
		}

		private void Update()
		{
			Action result;
			while (_mainThreadQueue.TryDequeue(out result))
			{
				result();
			}
		}

		private static void DoDebugLog(string input)
		{
			if (BoundConfig.debugLogging.Value)
			{
				Debug.Log((object)input);
			}
		}

		private void HandleSetVariable(ReFractCommand command)
		{
			_mainThreadQueue.Enqueue(delegate
			{
				HandleSetVariableInternal(command);
			});
		}

		private void HandleSetVariableInternal(ReFractCommand command)
		{
			DoDebugLog($"[Re:Fract] Received command for RT ID: {command.RenderTextureId}");
			if (command.RenderTextureId == 0)
			{
				Debug.LogWarning((object)"[Re:Fract] ERROR: Command has a zero RenderTextureId. Ignoring.");
				return;
			}
			RenderTextureAsset asset = RenderingManager.Instance.RenderTextures.GetAsset(command.RenderTextureId);
			if ((Object)(object)((asset != null) ? asset.Texture : null) != (Object)null && command.IsRemoveAlphaCommand)
			{
				int instanceID = ((Object)asset.Texture).GetInstanceID();
				DoDebugLog($"[Re:Fract] Setting RemoveAlpha for Unity Texture {instanceID} (Resonite {command.RenderTextureId}) to {command.BoolValue}");
				_removeAlphaCameras[instanceID] = command.BoolValue;
			}
			if (!_cameraCache.TryGetValue(command.RenderTextureId, out List<Camera> value) || value == null)
			{
				DoDebugLog($"[Re:Fract] Camera for {command.RenderTextureId} not in cache or is null. Searching...");
				if ((Object)(object)((asset != null) ? asset.Texture : null) == (Object)null)
				{
					if (command.IsRemoveAlphaCommand)
					{
						((MonoBehaviour)this).StartCoroutine(WaitForCameraAndApply(command));
					}
					return;
				}
				DoDebugLog($"[Re:Fract] Found render texture asset for {command.RenderTextureId}");
				value = FindCamerasRenderingTo(asset.Texture);
				if (value.Count == 0)
				{
					Debug.LogWarning((object)"[Re:Fract] ...but no camera was found. Waiting a few frames...");
					((MonoBehaviour)this).StartCoroutine(WaitForCameraAndApply(command));
					return;
				}
				_cameraCache[command.RenderTextureId] = value;
				DoDebugLog($"[Re:Fract] Found and cached {value.Count} cameras for ID {command.RenderTextureId}");
			}
			else
			{
				DoDebugLog($"[Re:Fract] Using cached cameras for ID {command.RenderTextureId}");
				if (command.IsRemoveAlphaCommand && value.Count > 0 && (Object)(object)value[0].targetTexture != (Object)null)
				{
					_removeAlphaCameras[((Object)value[0].targetTexture).GetInstanceID()] = command.BoolValue;
				}
			}
			value.RemoveAll((Camera c) => (Object)(object)c == (Object)null);
			if (value.Count == 0)
			{
				Debug.LogWarning((object)$"[Re:Fract] ERROR: All cached cameras for {command.RenderTextureId} were destroyed. Removing from cache.");
				if ((Object)(object)((asset != null) ? asset.Texture : null) != (Object)null)
				{
					_removeAlphaCameras.Remove(((Object)asset.Texture).GetInstanceID());
				}
				_cameraCache.Remove(command.RenderTextureId);
				return;
			}
			foreach (Camera item in value)
			{
				EnsurePostProcessVolume(item);
				if (!command.IsRemoveAlphaCommand)
				{
					ApplyCommand(item, command);
				}
			}
		}

		private IEnumerator WaitForCameraAndApply(ReFractCommand command)
		{
			for (int i = 0; i < 5; i++)
			{
				yield return null;
			}
			RenderTextureAsset asset = RenderingManager.Instance.RenderTextures.GetAsset(command.RenderTextureId);
			if ((Object)(object)((asset != null) ? asset.Texture : null) == (Object)null)
			{
				yield break;
			}
			if (command.IsRemoveAlphaCommand)
			{
				_removeAlphaCameras[((Object)asset.Texture).GetInstanceID()] = command.BoolValue;
			}
			List<Camera> list = FindCamerasRenderingTo(asset.Texture);
			if (list.Count > 0)
			{
				_cameraCache[command.RenderTextureId] = list;
				DoDebugLog($"[Re:Fract] Found {list.Count} cameras after waiting.");
				{
					foreach (Camera item in list)
					{
						EnsurePostProcessVolume(item);
						if (!command.IsRemoveAlphaCommand)
						{
							ApplyCommand(item, command);
						}
					}
					yield break;
				}
			}
			Debug.LogWarning((object)"[Re:Fract] ...still no camera found after waiting.");
		}

		private void EnsurePostProcessVolume(Camera camera)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_0326: Unknown result type (might be due to invalid IL or missing references)
			ReFractVolumeTracker reFractVolumeTracker = ((Component)camera).gameObject.GetComponent<ReFractVolumeTracker>();
			if ((Object)(object)reFractVolumeTracker == (Object)null)
			{
				reFractVolumeTracker = ((Component)camera).gameObject.AddComponent<ReFractVolumeTracker>();
			}
			int num = LayerMask.NameToLayer("Ignore Raycast");
			PostProcessLayer component = ((Component)camera).gameObject.GetComponent<PostProcessLayer>();
			if ((Object)(object)component != (Object)null)
			{
				component.volumeTrigger = ((Component)camera).transform;
				int num2 = 1 << num;
				if ((LayerMask.op_Implicit(component.volumeLayer) & num2) == 0)
				{
					DoDebugLog($"[Re:Fract] PostProcessLayer volumeLayer mask mismatch. Adding layer {num} (Ignore Raycast).");
					component.volumeLayer = LayerMask.op_Implicit(LayerMask.op_Implicit(component.volumeLayer) | num2);
				}
			}
			PostProcessVolume component2 = ((Component)camera).GetComponent<PostProcessVolume>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.Destroy((Object)(object)component2);
			}
			BoxCollider component3 = ((Component)camera).GetComponent<BoxCollider>();
			if ((Object)(object)component3 != (Object)null)
			{
				Object.Destroy((Object)(object)component3);
			}
			Transform val = ((Component)camera).transform.Find("ReFract_Volume");
			if ((Object)(object)val == (Object)null)
			{
				GameObject val2 = new GameObject("ReFract_Volume");
				val2.transform.SetParent(((Component)camera).transform, false);
				val2.layer = num;
				val = val2.transform;
			}
			reFractVolumeTracker.VolumeObject = ((Component)val).gameObject;
			PostProcessVolume val3 = ((Component)val).GetComponent<PostProcessVolume>();
			if ((Object)(object)val3 == (Object)null)
			{
				DoDebugLog("[Re:Fract] Creating PostProcessVolume on child of '" + ((Object)camera).name + "'.");
				val3 = ((Component)val).gameObject.AddComponent<PostProcessVolume>();
			}
			val3.isGlobal = false;
			if ((Object)(object)((Component)val).GetComponent<BoxCollider>() == (Object)null)
			{
				BoxCollider obj = ((Component)val).gameObject.AddComponent<BoxCollider>();
				((Collider)obj).isTrigger = true;
				obj.size = Vector3.one * 0.01f;
			}
			string text = $"ReFract_Profile_{((Object)camera).GetInstanceID()}";
			if ((Object)(object)val3.profile == (Object)null)
			{
				DoDebugLog("[Re:Fract] PostProcessVolume on '" + ((Object)camera).name + "' has no profile. Creating one and adding all settings.");
				PostProcessProfile val4 = ScriptableObject.CreateInstance<PostProcessProfile>();
				((Object)val4).name = text;
				val3.profile = val4;
				foreach (Type value in TypeLookups.Values)
				{
					if (typeof(PostProcessEffectSettings).IsAssignableFrom(value))
					{
						DoDebugLog("[Re:Fract] Adding setting '" + value.Name + "' to new profile.");
						val3.profile.AddSettings(value);
					}
				}
			}
			else if (((Object)val3.profile).name != text)
			{
				DoDebugLog("[Re:Fract] Ensuring unique profile for '" + ((Object)camera).name + "'.");
				PostProcessProfile val5 = Object.Instantiate<PostProcessProfile>(val3.profile);
				((Object)val5).name = text;
				val3.profile = val5;
				foreach (Type value2 in TypeLookups.Values)
				{
					if (typeof(PostProcessEffectSettings).IsAssignableFrom(value2) && !val5.HasSettings(value2))
					{
						val5.AddSettings(value2);
					}
				}
			}
			ColorGrading val6 = default(ColorGrading);
			if (val3.profile.TryGetSettings<ColorGrading>(ref val6))
			{
				((ParameterOverride<GradingMode>)(object)val6.gradingMode).value = (GradingMode)1;
				((ParameterOverride)val6.gradingMode).overrideState = true;
			}
		}

		private void ApplyCommand(Camera camera, ReFractCommand command)
		{
			DoDebugLog("[Re:Fract] Searching for component '" + command.ComponentName + "' on camera '" + ((Object)camera).name + "'");
			object obj = null;
			if (!TypeLookups.TryGetValue(command.ComponentName, out Type value))
			{
				Debug.LogWarning((object)("[Re:Fract] Unsupported Type " + command.ComponentName));
				return;
			}
			if (typeof(PostProcessEffectSettings).IsAssignableFrom(value))
			{
				PostProcessVolume componentInChildren = ((Component)camera).GetComponentInChildren<PostProcessVolume>();
				if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren.profile != (Object)null)
				{
					foreach (PostProcessEffectSettings setting in componentInChildren.profile.settings)
					{
						if (((object)setting).GetType() == value)
						{
							obj = setting;
							break;
						}
					}
					if (obj == null)
					{
						obj = componentInChildren.profile.AddSettings(value);
					}
				}
			}
			else
			{
				obj = ((Component)camera).GetComponent(value);
			}
			if (obj == null)
			{
				Debug.LogWarning((object)("[Re:Fract] ERROR: Camera '" + ((Object)camera).name + "' does not have or could not create component '" + command.ComponentName + "'"));
				return;
			}
			DoDebugLog("[Re:Fract] Found target '" + command.ComponentName + "'");
			object valueFromCommand = GetValueFromCommand(command);
			Type type = obj.GetType();
			if (command.ParameterName.EndsWith("!"))
			{
				string text = command.ParameterName.Substring(0, command.ParameterName.Length - 1);
				DoDebugLog($"[Re:Fract] Attempting to set property '{text}' on '{command.ComponentName} ({type.FullName})' to value '{valueFromCommand}'");
				Action<object, object> propSetter = Introspection.GetPropSetter(type, text);
				if (propSetter != null)
				{
					propSetter(obj, valueFromCommand);
					DoDebugLog("[Re:Fract] SUCCESS: Set property '" + text + "'.");
					return;
				}
				Debug.LogWarning((object)("[Re:Fract] ERROR: Could not find writable property '" + text + "' on component '" + command.ComponentName + "'"));
				return;
			}
			DoDebugLog($"[Re:Fract] Attempting to set '{command.ParameterName}' on '{command.ComponentName} ({type.FullName})' to value '{valueFromCommand}'");
			FieldInfo field = type.GetField(command.ParameterName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && typeof(ParameterOverride).IsAssignableFrom(field.FieldType))
			{
				object value2 = field.GetValue(obj);
				if (value2 != null)
				{
					Type type2 = value2.GetType();
					bool flag = false;
					FieldInfo field2 = type2.GetField("value", BindingFlags.Instance | BindingFlags.Public);
					if (field2 != null)
					{
						try
						{
							field2.SetValue(value2, valueFromCommand);
							DoDebugLog("[Re:Fract] Set 'value' field on ParameterOverride '" + command.ParameterName + "'.");
							flag = true;
						}
						catch (Exception arg)
						{
							Debug.LogWarning((object)$"[Re:Fract] Failed to set ParameterOverride field value: {arg}");
						}
					}
					if (!flag)
					{
						PropertyInfo property = type2.GetProperty("value");
						if (property != null && property.CanWrite)
						{
							try
							{
								property.SetValue(value2, valueFromCommand);
								DoDebugLog("[Re:Fract] Set 'value' property on ParameterOverride '" + command.ParameterName + "'.");
								flag = true;
							}
							catch (Exception arg2)
							{
								Debug.LogWarning((object)$"[Re:Fract] Failed to set ParameterOverride property value: {arg2}");
							}
						}
					}
					if (flag)
					{
						FieldInfo field3 = type2.GetField("overrideState", BindingFlags.Instance | BindingFlags.Public);
						if (field3 != null)
						{
							field3.SetValue(value2, true);
							DoDebugLog("[Re:Fract] SUCCESS: Activated override for '" + command.ParameterName + "'.");
						}
						else
						{
							Debug.LogWarning((object)("[Re:Fract] Could not find 'overrideState' field on '" + type2.Name + "'. The setting may not apply visually."));
						}
						return;
					}
				}
			}
			Action<object, object> propSetter2 = Introspection.GetPropSetter(type, command.ParameterName);
			if (propSetter2 != null)
			{
				propSetter2(obj, valueFromCommand);
				DoDebugLog("[Re:Fract] SUCCESS: Set property '" + command.ParameterName + "'.");
				return;
			}
			Introspection.RefAction<object, object> fieldSetter = Introspection.GetFieldSetter(type, command.ParameterName);
			if (fieldSetter != null)
			{
				fieldSetter(ref obj, valueFromCommand);
				DoDebugLog("[Re:Fract] SUCCESS: Set field '" + command.ParameterName + "'.");
				return;
			}
			Debug.LogWarning((object)("[Re:Fract] ERROR: Could not find writable property or field '" + command.ParameterName + "' on component '" + command.ComponentName + "'"));
		}

		private static object GetValueFromCommand(ReFractCommand command)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			return command.ValueType switch
			{
				ReFractCommandValueType.Int => command.IntValue, 
				ReFractCommandValueType.Float => command.FloatValue, 
				ReFractCommandValueType.Bool => command.BoolValue, 
				ReFractCommandValueType.Color => (object)new Color(command.ColorValue.r, command.ColorValue.g, command.ColorValue.b, command.ColorValue.a), 
				ReFractCommandValueType.Vector2 => (object)new Vector2(command.Vector2Value.x, command.Vector2Value.y), 
				ReFractCommandValueType.Vector4 => (object)new Vector4(command.Vector4Value.x, command.Vector4Value.y, command.Vector4Value.z, command.Vector4Value.w), 
				ReFractCommandValueType.String => command.StringValue, 
				_ => throw new ArgumentOutOfRangeException(), 
			};
		}

		private static List<Camera> FindCamerasRenderingTo(RenderTexture target)
		{
			DoDebugLog(string.Format("[Re:Fract] Searching for RenderTexture {0} @ {1}", Object.op_Implicit((Object)(object)target) ? ((Object)target).name : "NULL TARGET", Object.op_Implicit((Object)(object)target) ? ((object)((Object)target).GetInstanceID()) : "N/A"));
			Camera[] array = Object.FindObjectsOfType<Camera>();
			List<Camera> list = new List<Camera>();
			Camera[] array2 = array;
			foreach (Camera val in array2)
			{
				DoDebugLog(string.Format("[Re:Fract] Camera {0} @ {1} --> {2} @ {3}...", ((Object)val).name, ((Object)val).GetInstanceID(), Object.op_Implicit((Object)(object)val.targetTexture) ? ((Object)val.targetTexture).name : "NULL TARGET", Object.op_Implicit((Object)(object)val.targetTexture) ? ((object)((Object)val.targetTexture).GetInstanceID()) : "N/A"));
				if ((Object)(object)val.targetTexture == (Object)(object)target)
				{
					list.Add(val);
				}
			}
			if (list.Count == 0)
			{
				Debug.LogWarning((object)"[Re:Fract] No camera found rendering to the specified RenderTexture.");
			}
			return list;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}