Decompiled source of ShadersPlus v1.0.0

BonelabShaders.dll

Decompiled 20 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BoneLib.BoneMenu;
using BonelabShaders;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ShadersMod), "Bonelab Shaders", "3.0.0", "Wakey", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BonelabShaders
{
	internal static class DepthShaders
	{
		private static bool _inited;

		private static bool _available;

		private static AssetBundle _bundle;

		private static Material _pixelMat;

		private static Material _acidMat;

		private static RTHandle _tmp;

		private static int _tw;

		private static int _th;

		private static int _ts;

		private static bool _loggedEvent;

		private static bool _loggedFirstBlit;

		private static bool _loggedError;

		private const bool _experimentalBlit = false;

		public static bool PixelOn;

		public static bool AcidWarpOn;

		public static float PixelNearBlock = 2f;

		public static float PixelFarBlock = 24f;

		public static float PixelNearDist = 1f;

		public static float PixelFarDist = 25f;

		public static float WarpAmp = 0.03f;

		public static float WarpFreq = 16f;

		public static float WarpSpeed = 1.2f;

		public static float WarpNearDist = 3f;

		public static float WarpFarDist = 40f;

		public static bool Available => _available;

		public static void Init(string bundlePath, Harmony harmony)
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_0167: 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_0179: Expected O, but got Unknown
			if (_inited)
			{
				return;
			}
			_inited = true;
			try
			{
				MelonLogger.Msg("[Depth] bundle path: " + bundlePath + " (exists=" + File.Exists(bundlePath) + ")");
				if (!File.Exists(bundlePath))
				{
					MelonLogger.Msg("[Depth] no shader bundle - fallbacks only.");
					return;
				}
				_bundle = AssetBundle.LoadFromFile(bundlePath);
				if ((Object)(object)_bundle == (Object)null)
				{
					MelonLogger.Msg("[Depth] LoadFromFile null; trying LoadFromMemory...");
					_bundle = AssetBundle.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(File.ReadAllBytes(bundlePath)));
				}
				if ((Object)(object)_bundle == (Object)null)
				{
					MelonLogger.Warning("[Depth] bundle failed to load.");
					return;
				}
				Shader val = null;
				foreach (Object item in (Il2CppArrayBase<Object>)(object)_bundle.LoadAllAssets())
				{
					Shader val2 = ((Il2CppObjectBase)item).TryCast<Shader>();
					if ((Object)(object)val2 != (Object)null)
					{
						val = val2;
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					MelonLogger.Warning("[Depth] shader not in bundle.");
					return;
				}
				MelonLogger.Msg("[Depth] loaded shader: " + ((Object)val).name + " (supported=" + val.isSupported + ")");
				_pixelMat = new Material(val)
				{
					hideFlags = (HideFlags)61
				};
				_acidMat = new Material(val)
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)(object)_pixelMat);
				Object.DontDestroyOnLoad((Object)(object)_acidMat);
				UniversalRenderPipelineAsset val3 = Rp.Get();
				if ((Object)(object)val3 != (Object)null)
				{
					val3.supportsCameraDepthTexture = true;
				}
				_available = false;
				MelonLogger.Msg("[Depth] bundle + shader load fine, but the VR depth blit is disabled for stability (it rendered but crashed the headset present). Color Acid + uniform Pixel fallbacks are active.");
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("[Depth] init failed: " + ex);
			}
		}

		private static void OnEndCamera(ScriptableRenderContext context, Camera camera)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: 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_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_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			if (!_available || (Object)(object)camera == (Object)null || (int)camera.cameraType != 1)
			{
				return;
			}
			if (!_loggedEvent)
			{
				_loggedEvent = true;
				MelonLogger.Msg("[Depth] endCameraRendering fired OK on '" + ((Object)camera).name + "' (no blit yet).");
			}
			if (!PixelOn && !AcidWarpOn)
			{
				return;
			}
			try
			{
				RenderTexture val = camera.activeTexture;
				if ((Object)(object)val == (Object)null)
				{
					val = RenderTexture.active;
				}
				if ((Object)(object)val == (Object)null)
				{
					if (!_loggedError)
					{
						_loggedError = true;
						MelonLogger.Warning("[Depth] no active camera RenderTexture to blit.");
					}
					return;
				}
				RenderTextureDescriptor descriptor = val.descriptor;
				((RenderTextureDescriptor)(ref descriptor)).depthBufferBits = 0;
				((RenderTextureDescriptor)(ref descriptor)).msaaSamples = 1;
				EnsureTemp(descriptor);
				if (_tmp != null)
				{
					if (!_loggedFirstBlit)
					{
						MelonLogger.Msg("[Depth] attempting blit: " + ((RenderTextureDescriptor)(ref descriptor)).width + "x" + ((RenderTextureDescriptor)(ref descriptor)).height + " fmt=" + ((object)((RenderTextureDescriptor)(ref descriptor)).graphicsFormat/*cast due to .constrained prefix*/).ToString() + " dim=" + ((object)((RenderTextureDescriptor)(ref descriptor)).dimension/*cast due to .constrained prefix*/).ToString() + " slices=" + ((RenderTextureDescriptor)(ref descriptor)).volumeDepth);
					}
					CommandBuffer val2 = CommandBufferPool.Get("BonelabShaders");
					RTHandle val3 = RTHandles.Alloc(val);
					if (PixelOn)
					{
						_pixelMat.SetFloat("_MinBlock", PixelNearBlock);
						_pixelMat.SetFloat("_MaxBlock", PixelFarBlock);
						_pixelMat.SetFloat("_NearDist", PixelNearDist);
						_pixelMat.SetFloat("_FarDist", PixelFarDist);
						Blitter.BlitCameraTexture(val2, val3, _tmp, _pixelMat, 0);
						val2.CopyTexture(RTHandle.op_Implicit(_tmp), RTHandle.op_Implicit(val3));
					}
					if (AcidWarpOn)
					{
						_acidMat.SetFloat("_WarpAmp", WarpAmp);
						_acidMat.SetFloat("_WarpFreq", WarpFreq);
						_acidMat.SetFloat("_WarpSpeed", WarpSpeed);
						_acidMat.SetFloat("_NearCut", WarpNearDist);
						_acidMat.SetFloat("_FarCut", WarpFarDist);
						_acidMat.SetFloat("_EffectTime", Time.time);
						Blitter.BlitCameraTexture(val2, val3, _tmp, _acidMat, 1);
						val2.CopyTexture(RTHandle.op_Implicit(_tmp), RTHandle.op_Implicit(val3));
					}
					((ScriptableRenderContext)(ref context)).ExecuteCommandBuffer(val2);
					val2.Clear();
					CommandBufferPool.Release(val2);
					RTHandles.Release(val3);
					if (!_loggedFirstBlit)
					{
						_loggedFirstBlit = true;
						MelonLogger.Msg("[Depth] blit executed on '" + ((Object)camera).name + "'.");
					}
				}
			}
			catch (Exception ex)
			{
				if (!_loggedError)
				{
					_loggedError = true;
					MelonLogger.Warning("[Depth] blit failed (full stack): " + ex);
				}
			}
		}

		private static void EnsureTemp(RenderTextureDescriptor d)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (_tmp == null || _tw != ((RenderTextureDescriptor)(ref d)).width || _th != ((RenderTextureDescriptor)(ref d)).height || _ts != ((RenderTextureDescriptor)(ref d)).volumeDepth)
			{
				if (_tmp != null)
				{
					RTHandles.Release(_tmp);
					_tmp = null;
				}
				_tmp = RTHandles.Alloc(((RenderTextureDescriptor)(ref d)).width, ((RenderTextureDescriptor)(ref d)).height, ((RenderTextureDescriptor)(ref d)).volumeDepth, (DepthBits)0, ((RenderTextureDescriptor)(ref d)).graphicsFormat, (FilterMode)0, (TextureWrapMode)1, ((RenderTextureDescriptor)(ref d)).dimension, false, false, true, false, 1, 0f, (MSAASamples)1, false, false, (RenderTextureMemoryless)0, "BonelabShaders_Tmp");
				_tw = ((RenderTextureDescriptor)(ref d)).width;
				_th = ((RenderTextureDescriptor)(ref d)).height;
				_ts = ((RenderTextureDescriptor)(ref d)).volumeDepth;
			}
		}
	}
	public enum AcidStyle
	{
		Rainbow,
		Fever,
		Melt,
		Kaleidoscope,
		Vaporwave
	}
	public enum PixelPalette
	{
		None,
		Doom,
		GameBoy,
		Grayscale,
		Vaporwave,
		Sepia
	}
	internal static class Rp
	{
		public static UniversalRenderPipelineAsset Get()
		{
			RenderPipelineAsset val = GraphicsSettings.currentRenderPipeline;
			if ((Object)(object)val == (Object)null)
			{
				val = QualitySettings.renderPipeline;
			}
			if (!((Object)(object)val == (Object)null))
			{
				return ((Il2CppObjectBase)val).TryCast<UniversalRenderPipelineAsset>();
			}
			return null;
		}

		public static Volume MakeGlobalVolume(string name, float priority, out VolumeProfile profile)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			GameObject val = new GameObject(name)
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			Volume obj = val.AddComponent<Volume>();
			obj.isGlobal = true;
			obj.priority = priority;
			obj.weight = 0f;
			profile = ((Il2CppObjectBase)ScriptableObject.CreateInstance(Il2CppType.Of<VolumeProfile>())).Cast<VolumeProfile>();
			((Object)profile).hideFlags = (HideFlags)61;
			obj.profile = profile;
			return obj;
		}
	}
	internal static class RenderScaleControl
	{
		private static bool _captured;

		private static float _defScale = 1f;

		private static UpscalingFilterSelection _defFilter = (UpscalingFilterSelection)0;

		public static void Set(float scale, UpscalingFilterSelection filter)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			UniversalRenderPipelineAsset val = Rp.Get();
			if (!((Object)(object)val == (Object)null))
			{
				if (!_captured)
				{
					_defScale = val.renderScale;
					_defFilter = val.upscalingFilter;
					_captured = true;
				}
				if (Mathf.Abs(val.renderScale - scale) > 0.001f)
				{
					val.renderScale = scale;
				}
				if (val.upscalingFilter != filter)
				{
					val.upscalingFilter = filter;
				}
			}
		}

		public static void Restore()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			UniversalRenderPipelineAsset val = Rp.Get();
			if (!((Object)(object)val == (Object)null) && _captured)
			{
				if (Mathf.Abs(val.renderScale - _defScale) > 0.001f)
				{
					val.renderScale = _defScale;
				}
				if (val.upscalingFilter != _defFilter)
				{
					val.upscalingFilter = _defFilter;
				}
			}
		}
	}
	internal class AcidEffect
	{
		private Volume _volume;

		private ColorAdjustments _color;

		private ChromaticAberration _chroma;

		private LensDistortion _lens;

		private Vignette _vig;

		private Bloom _bloom;

		private SplitToning _split;

		private PaniniProjection _panini;

		private WhiteBalance _wb;

		private bool _built;

		private bool _on;

		private void Build()
		{
			if (!_built)
			{
				_volume = Rp.MakeGlobalVolume("BonelabShaders_Acid", 1000f, out var profile);
				_color = profile.Add<ColorAdjustments>(true);
				_chroma = profile.Add<ChromaticAberration>(true);
				_lens = profile.Add<LensDistortion>(true);
				_vig = profile.Add<Vignette>(true);
				_bloom = profile.Add<Bloom>(true);
				_split = profile.Add<SplitToning>(true);
				_panini = profile.Add<PaniniProjection>(true);
				_wb = profile.Add<WhiteBalance>(true);
				_built = true;
				MelonLogger.Msg("[Acid] volume built");
			}
		}

		private static float Wave(float t, float freq)
		{
			return Mathf.Sin(t * freq);
		}

		private static float Wave01(float t, float freq)
		{
			return 0.5f + 0.5f * Mathf.Sin(t * freq);
		}

		private static float Hue360(float t, float speed)
		{
			return Mathf.Repeat(t * speed, 360f) - 180f;
		}

		public void Tick(AcidStyle style, float intensity, float speed)
		{
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_0618: Unknown result type (might be due to invalid IL or missing references)
			//IL_064e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Unknown result type (might be due to invalid IL or missing references)
			Build();
			if (!((Object)(object)_volume == (Object)null))
			{
				if (!_on)
				{
					((Component)_volume).gameObject.SetActive(true);
					_on = true;
				}
				intensity = Mathf.Clamp(intensity, 0f, 2f);
				speed = Mathf.Clamp(speed, 0.1f, 3f);
				_volume.weight = Mathf.Clamp01(intensity);
				float num = Time.time * speed;
				((VolumeParameter<float>)(object)_color.hueShift).value = 0f;
				((VolumeParameter<float>)(object)_color.saturation).value = 0f;
				((VolumeParameter<float>)(object)_color.contrast).value = 0f;
				((VolumeParameter<float>)(object)_color.postExposure).value = 0f;
				((VolumeParameter<Color>)(object)_color.colorFilter).value = Color.white;
				((VolumeParameter<float>)(object)_chroma.intensity).value = 0f;
				((VolumeParameter<float>)(object)_lens.intensity).value = 0f;
				((VolumeParameter<float>)(object)_lens.scale).value = 1f;
				((VolumeParameter<Vector2>)(object)_lens.center).value = Vector2.zero;
				((VolumeParameter<float>)(object)_vig.intensity).value = 0f;
				((VolumeParameter<Color>)(object)_vig.color).value = Color.black;
				((VolumeParameter<float>)(object)_vig.smoothness).value = 0.5f;
				((VolumeParameter<float>)(object)_bloom.intensity).value = 0f;
				((VolumeParameter<float>)(object)_bloom.threshold).value = 1.1f;
				((VolumeParameter<Color>)(object)_split.shadows).value = new Color(0.5f, 0.5f, 0.5f);
				((VolumeParameter<Color>)(object)_split.highlights).value = new Color(0.5f, 0.5f, 0.5f);
				((VolumeParameter<float>)(object)_split.balance).value = 0f;
				((VolumeParameter<float>)(object)_panini.distance).value = 0f;
				((VolumeParameter<float>)(object)_wb.temperature).value = 0f;
				((VolumeParameter<float>)(object)_wb.tint).value = 0f;
				switch (style)
				{
				case AcidStyle.Rainbow:
					((VolumeParameter<float>)(object)_color.hueShift).value = Hue360(num, 45f);
					((VolumeParameter<float>)(object)_color.saturation).value = 35f * intensity;
					((VolumeParameter<float>)(object)_color.postExposure).value = Wave(num, 0.8f) * 0.2f * intensity;
					((VolumeParameter<float>)(object)_bloom.threshold).value = 1f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = 0.4f * intensity;
					((VolumeParameter<float>)(object)_chroma.intensity).value = 0.08f * intensity;
					break;
				case AcidStyle.Fever:
					((VolumeParameter<float>)(object)_color.hueShift).value = Hue360(num, 150f);
					((VolumeParameter<float>)(object)_color.saturation).value = Mathf.Clamp(45f + Wave(num, 3f) * 40f * intensity, -100f, 100f);
					((VolumeParameter<float>)(object)_color.contrast).value = Mathf.Clamp(Wave(num, 2.2f) * 30f * intensity, -100f, 100f);
					((VolumeParameter<float>)(object)_chroma.intensity).value = Mathf.Clamp01((0.25f + 0.5f * Wave01(num, 4f)) * intensity);
					((VolumeParameter<float>)(object)_vig.intensity).value = (0.15f + 0.2f * Wave01(num, 3f)) * intensity;
					((VolumeParameter<Color>)(object)_vig.color).value = Color.HSVToRGB(Mathf.Repeat(num * 0.15f, 1f), 1f, 1f);
					((VolumeParameter<float>)(object)_bloom.threshold).value = 0.9f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = (0.4f + Wave01(num, 2f) * 0.6f) * intensity;
					break;
				case AcidStyle.Melt:
					((VolumeParameter<float>)(object)_color.hueShift).value = Hue360(num, 18f);
					((VolumeParameter<float>)(object)_color.saturation).value = Mathf.Clamp(40f + Wave(num, 0.6f) * 30f * intensity, -100f, 100f);
					((VolumeParameter<float>)(object)_color.contrast).value = Wave(num, 0.4f) * 18f * intensity;
					((VolumeParameter<float>)(object)_color.postExposure).value = Wave(num, 0.35f) * 0.25f * intensity;
					((VolumeParameter<float>)(object)_chroma.intensity).value = Mathf.Clamp01((0.45f + 0.35f * Wave01(num, 0.8f)) * intensity);
					((VolumeParameter<Color>)(object)_split.shadows).value = Color.HSVToRGB(Mathf.Repeat(num * 0.04f, 1f), 0.8f, 1f);
					((VolumeParameter<Color>)(object)_split.highlights).value = Color.HSVToRGB(Mathf.Repeat(num * 0.04f + 0.35f, 1f), 0.8f, 1f);
					((VolumeParameter<float>)(object)_split.balance).value = Wave(num, 0.5f) * 40f;
					((VolumeParameter<float>)(object)_bloom.threshold).value = 1f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = (0.3f + Wave01(num, 0.5f) * 0.4f) * intensity;
					break;
				case AcidStyle.Kaleidoscope:
					((VolumeParameter<float>)(object)_color.hueShift).value = Hue360(num, 90f);
					((VolumeParameter<float>)(object)_color.saturation).value = 55f * intensity;
					((VolumeParameter<Color>)(object)_split.shadows).value = Color.HSVToRGB(Mathf.Repeat(num * 0.1f, 1f), 0.9f, 1f);
					((VolumeParameter<Color>)(object)_split.highlights).value = Color.HSVToRGB(Mathf.Repeat(num * 0.1f + 0.5f, 1f), 0.9f, 1f);
					((VolumeParameter<float>)(object)_split.balance).value = Wave(num, 1.3f) * 50f;
					((VolumeParameter<float>)(object)_chroma.intensity).value = Mathf.Clamp01(0.2f * intensity);
					((VolumeParameter<float>)(object)_bloom.threshold).value = 1f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = 0.3f * intensity;
					break;
				case AcidStyle.Vaporwave:
					((VolumeParameter<float>)(object)_color.hueShift).value = -20f + Wave(num, 0.3f) * 15f;
					((VolumeParameter<float>)(object)_color.saturation).value = 30f * intensity;
					((VolumeParameter<float>)(object)_color.contrast).value = 8f * intensity;
					((VolumeParameter<Color>)(object)_split.shadows).value = new Color(0.55f, 0.25f, 0.7f);
					((VolumeParameter<Color>)(object)_split.highlights).value = new Color(0.25f, 0.75f, 0.95f);
					((VolumeParameter<float>)(object)_split.balance).value = 10f;
					((VolumeParameter<float>)(object)_wb.temperature).value = -18f * intensity;
					((VolumeParameter<float>)(object)_bloom.threshold).value = 1f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = 0.5f * intensity;
					break;
				}
			}
		}

		public void Disable()
		{
			_on = false;
			if ((Object)(object)_volume != (Object)null)
			{
				_volume.weight = 0f;
				((Component)_volume).gameObject.SetActive(false);
			}
		}

		public void EnsureDisabled()
		{
			if (_on)
			{
				Disable();
			}
		}
	}
	internal class PixelEffect
	{
		private Volume _grade;

		private ColorAdjustments _c;

		private SplitToning _s;

		private Vignette _v;

		private bool _gradeBuilt;

		private PixelPalette _curPalette = (PixelPalette)(-1);

		public void Apply(float pixelSize, PixelPalette palette)
		{
			pixelSize = Mathf.Clamp(pixelSize, 1f, 32f);
			RenderScaleControl.Set(Mathf.Clamp(1f / pixelSize, 0.02f, 1f), (UpscalingFilterSelection)2);
			SetPalette(palette);
		}

		public void EnsureApplied(float pixelSize, PixelPalette palette)
		{
			Apply(pixelSize, palette);
		}

		public void Disable()
		{
			RenderScaleControl.Restore();
			if ((Object)(object)_grade != (Object)null)
			{
				_grade.weight = 0f;
				((Component)_grade).gameObject.SetActive(false);
			}
			_curPalette = (PixelPalette)(-1);
		}

		private void BuildGrade()
		{
			if (!_gradeBuilt)
			{
				_grade = Rp.MakeGlobalVolume("BonelabShaders_PixelGrade", 950f, out var profile);
				_c = profile.Add<ColorAdjustments>(true);
				_s = profile.Add<SplitToning>(true);
				_v = profile.Add<Vignette>(true);
				_gradeBuilt = true;
			}
		}

		private void SetPalette(PixelPalette palette)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			if (palette == _curPalette)
			{
				return;
			}
			_curPalette = palette;
			if (palette == PixelPalette.None)
			{
				if ((Object)(object)_grade != (Object)null)
				{
					_grade.weight = 0f;
					((Component)_grade).gameObject.SetActive(false);
				}
				return;
			}
			BuildGrade();
			((Component)_grade).gameObject.SetActive(true);
			_grade.weight = 1f;
			((VolumeParameter<float>)(object)_c.saturation).value = 0f;
			((VolumeParameter<float>)(object)_c.contrast).value = 0f;
			((VolumeParameter<float>)(object)_c.postExposure).value = 0f;
			((VolumeParameter<Color>)(object)_c.colorFilter).value = Color.white;
			((VolumeParameter<Color>)(object)_s.shadows).value = new Color(0.5f, 0.5f, 0.5f);
			((VolumeParameter<Color>)(object)_s.highlights).value = new Color(0.5f, 0.5f, 0.5f);
			((VolumeParameter<float>)(object)_s.balance).value = 0f;
			((VolumeParameter<float>)(object)_v.intensity).value = 0f;
			((VolumeParameter<Color>)(object)_v.color).value = Color.black;
			((VolumeParameter<float>)(object)_v.smoothness).value = 0.5f;
			switch (palette)
			{
			case PixelPalette.Doom:
				((VolumeParameter<float>)(object)_c.contrast).value = 22f;
				((VolumeParameter<float>)(object)_c.saturation).value = -18f;
				((VolumeParameter<float>)(object)_c.postExposure).value = -0.12f;
				((VolumeParameter<Color>)(object)_c.colorFilter).value = new Color(1f, 0.86f, 0.72f);
				((VolumeParameter<float>)(object)_v.intensity).value = 0.35f;
				((VolumeParameter<float>)(object)_v.smoothness).value = 0.5f;
				break;
			case PixelPalette.GameBoy:
				((VolumeParameter<float>)(object)_c.saturation).value = -100f;
				((VolumeParameter<float>)(object)_c.contrast).value = 45f;
				((VolumeParameter<float>)(object)_c.postExposure).value = -0.05f;
				((VolumeParameter<Color>)(object)_c.colorFilter).value = new Color(0.61f, 0.83f, 0.3f);
				break;
			case PixelPalette.Grayscale:
				((VolumeParameter<float>)(object)_c.saturation).value = -100f;
				((VolumeParameter<float>)(object)_c.contrast).value = 12f;
				break;
			case PixelPalette.Vaporwave:
				((VolumeParameter<float>)(object)_c.saturation).value = 28f;
				((VolumeParameter<float>)(object)_c.contrast).value = 6f;
				((VolumeParameter<Color>)(object)_s.shadows).value = new Color(0.55f, 0.25f, 0.7f);
				((VolumeParameter<Color>)(object)_s.highlights).value = new Color(0.25f, 0.75f, 0.95f);
				((VolumeParameter<float>)(object)_s.balance).value = 10f;
				break;
			case PixelPalette.Sepia:
				((VolumeParameter<float>)(object)_c.saturation).value = -100f;
				((VolumeParameter<float>)(object)_c.contrast).value = 15f;
				((VolumeParameter<Color>)(object)_c.colorFilter).value = new Color(1f, 0.82f, 0.62f);
				break;
			}
		}
	}
	internal static class Hud
	{
		public static Material Unlit(Color color)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Universal Render Pipeline/Unlit");
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Sprites/Default");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = Shader.Find("Unlit/Color");
			}
			Material val2 = new Material(val)
			{
				hideFlags = (HideFlags)61
			};
			try
			{
				val2.SetColor("_BaseColor", color);
			}
			catch
			{
			}
			try
			{
				val2.color = color;
			}
			catch
			{
			}
			val2.renderQueue = 4500;
			return val2;
		}

		public static GameObject Quad(Transform parent, Color color, Vector3 localPos, Vector3 localScale)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)5);
			((Object)obj).hideFlags = (HideFlags)61;
			Collider component = obj.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			obj.transform.SetParent(parent, false);
			obj.transform.localPosition = localPos;
			obj.transform.localScale = localScale;
			obj.transform.localRotation = Quaternion.identity;
			MeshRenderer component2 = obj.GetComponent<MeshRenderer>();
			((Renderer)component2).material = Unlit(color);
			((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)component2).receiveShadows = false;
			return obj;
		}

		public static Font GetFont()
		{
			try
			{
				Object builtinResource = Resources.GetBuiltinResource(Il2CppType.Of<Font>(), "LegacyRuntime.ttf");
				if (builtinResource != (Object)null)
				{
					return ((Il2CppObjectBase)builtinResource).Cast<Font>();
				}
			}
			catch
			{
			}
			try
			{
				return Font.CreateDynamicFontFromOSFont("Arial", 32);
			}
			catch
			{
			}
			return null;
		}

		public static void Follow(GameObject root, Transform cam, float distance)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)root == (Object)null) && !((Object)(object)cam == (Object)null))
			{
				root.transform.position = cam.position + cam.forward * distance;
				root.transform.rotation = cam.rotation;
			}
		}
	}
	internal class BodycamEffect
	{
		private Volume _volume;

		private ColorAdjustments _color;

		private ChromaticAberration _chroma;

		private Vignette _vig;

		private FilmGrain _grain;

		private LensDistortion _lens;

		private WhiteBalance _wb;

		private Bloom _bloom;

		private bool _built;

		private bool _on;

		private GameObject _hud;

		private GameObject _dot;

		private TextMesh _text;

		private bool _hudBuilt;

		private bool _hudFailed;

		private bool _dotOn = true;

		private float _blink;

		private float _startTime = -1f;

		private void Build()
		{
			if (!_built)
			{
				_volume = Rp.MakeGlobalVolume("BonelabShaders_Bodycam", 1100f, out var profile);
				_color = profile.Add<ColorAdjustments>(true);
				_chroma = profile.Add<ChromaticAberration>(true);
				_vig = profile.Add<Vignette>(true);
				_grain = profile.Add<FilmGrain>(true);
				_lens = profile.Add<LensDistortion>(true);
				_wb = profile.Add<WhiteBalance>(true);
				_bloom = profile.Add<Bloom>(true);
				_built = true;
				MelonLogger.Msg("[Bodycam] volume built");
			}
		}

		public void Tick(float intensity)
		{
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			Build();
			if (!((Object)(object)_volume == (Object)null))
			{
				if (!_on)
				{
					((Component)_volume).gameObject.SetActive(true);
					_on = true;
					_startTime = Time.time;
				}
				intensity = Mathf.Clamp(intensity, 0f, 1.5f);
				_volume.weight = Mathf.Clamp01(intensity);
				float time = Time.time;
				((VolumeParameter<float>)(object)_color.saturation).value = -28f * intensity;
				((VolumeParameter<float>)(object)_color.contrast).value = 18f * intensity;
				((VolumeParameter<float>)(object)_color.postExposure).value = Mathf.Sin(time * 3.3f) * 0.08f * intensity;
				((VolumeParameter<Color>)(object)_color.colorFilter).value = new Color(0.92f, 1f, 0.95f);
				((VolumeParameter<float>)(object)_chroma.intensity).value = Mathf.Clamp01(0.28f * intensity);
				((VolumeParameter<float>)(object)_vig.intensity).value = Mathf.Clamp01((0.42f + Mathf.Sin(time * 2f) * 0.03f) * intensity);
				((VolumeParameter<float>)(object)_vig.smoothness).value = 0.4f;
				((VolumeParameter<Color>)(object)_vig.color).value = Color.black;
				((VolumeParameter<FilmGrainLookup>)(object)_grain.type).value = (FilmGrainLookup)8;
				((VolumeParameter<float>)(object)_grain.intensity).value = Mathf.Clamp01(0.55f * intensity);
				((VolumeParameter<float>)(object)_grain.response).value = 0.8f;
				((VolumeParameter<float>)(object)_lens.intensity).value = -0.18f * intensity;
				((VolumeParameter<float>)(object)_wb.temperature).value = 6f * intensity;
				((VolumeParameter<float>)(object)_bloom.threshold).value = 1.05f;
				((VolumeParameter<float>)(object)_bloom.intensity).value = 0.35f * intensity;
			}
		}

		public void UpdateHud(Transform cam, bool showRec)
		{
			if (!showRec)
			{
				if ((Object)(object)_hud != (Object)null)
				{
					_hud.SetActive(false);
				}
			}
			else
			{
				if (_hudFailed)
				{
					return;
				}
				if (!_hudBuilt)
				{
					BuildHud();
				}
				if ((Object)(object)_hud == (Object)null)
				{
					return;
				}
				_hud.SetActive(true);
				Hud.Follow(_hud, cam, 0.5f);
				_blink += Time.deltaTime;
				if (_blink > 0.55f)
				{
					_blink = 0f;
					_dotOn = !_dotOn;
					if ((Object)(object)_dot != (Object)null)
					{
						_dot.SetActive(_dotOn);
					}
				}
				if ((Object)(object)_text != (Object)null)
				{
					float num = ((_startTime < 0f) ? 0f : (Time.time - _startTime));
					int num2 = (int)(num / 60f);
					int num3 = (int)(num % 60f);
					_text.text = "REC  " + num2.ToString("00") + ":" + num3.ToString("00");
				}
			}
		}

		private void BuildHud()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0092: Expected O, but got Unknown
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			_hudBuilt = true;
			try
			{
				_hud = new GameObject("BonelabShaders_RECHUD")
				{
					hideFlags = (HideFlags)61
				};
				Object.DontDestroyOnLoad((Object)(object)_hud);
				_dot = Hud.Quad(_hud.transform, Color.red, new Vector3(-0.16f, 0.11f, 0f), new Vector3(0.015f, 0.015f, 0.015f));
				Font font = Hud.GetFont();
				if ((Object)(object)font != (Object)null)
				{
					GameObject val = new GameObject("REC_text")
					{
						hideFlags = (HideFlags)61
					};
					val.transform.SetParent(_hud.transform, false);
					val.transform.localPosition = new Vector3(-0.145f, 0.11f, 0f);
					val.transform.localScale = Vector3.one * 0.0016f;
					_text = val.AddComponent<TextMesh>();
					_text.font = font;
					_text.fontSize = 64;
					_text.color = Color.red;
					_text.anchor = (TextAnchor)3;
					_text.text = "REC  00:00";
					MeshRenderer component = val.GetComponent<MeshRenderer>();
					if ((Object)(object)component != (Object)null)
					{
						((Renderer)component).material = font.material;
					}
				}
				MelonLogger.Msg("[Bodycam] REC HUD built" + (((Object)(object)_text == (Object)null) ? " (no font, dot only)" : ""));
			}
			catch (Exception ex)
			{
				_hudFailed = true;
				MelonLogger.Warning("[Bodycam] HUD build failed (post effect still works): " + ex.Message);
			}
		}

		public void Disable()
		{
			_on = false;
			_startTime = -1f;
			if ((Object)(object)_volume != (Object)null)
			{
				_volume.weight = 0f;
				((Component)_volume).gameObject.SetActive(false);
			}
			if ((Object)(object)_hud != (Object)null)
			{
				_hud.SetActive(false);
			}
		}

		public void EnsureDisabled()
		{
			if (_on)
			{
				Disable();
			}
		}
	}
	internal class CinematicEffect
	{
		private Volume _volume;

		private ColorAdjustments _color;

		private Tonemapping _tone;

		private SplitToning _split;

		private Bloom _bloom;

		private Vignette _vig;

		private WhiteBalance _wb;

		private bool _built;

		private bool _on;

		private void Build()
		{
			if (!_built)
			{
				_volume = Rp.MakeGlobalVolume("BonelabShaders_Cinematic", 1050f, out var profile);
				_color = profile.Add<ColorAdjustments>(true);
				_tone = profile.Add<Tonemapping>(true);
				_split = profile.Add<SplitToning>(true);
				_bloom = profile.Add<Bloom>(true);
				_vig = profile.Add<Vignette>(true);
				_wb = profile.Add<WhiteBalance>(true);
				_built = true;
				MelonLogger.Msg("[Cinematic] volume built");
			}
		}

		public void Tick(float intensity)
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			Build();
			if (!((Object)(object)_volume == (Object)null))
			{
				if (!_on)
				{
					((Component)_volume).gameObject.SetActive(true);
					_on = true;
				}
				intensity = Mathf.Clamp(intensity, 0f, 1.5f);
				_volume.weight = Mathf.Clamp01(intensity);
				float time = Time.time;
				((VolumeParameter<TonemappingMode>)(object)_tone.mode).value = (TonemappingMode)2;
				((VolumeParameter<float>)(object)_color.contrast).value = 16f * intensity;
				((VolumeParameter<float>)(object)_color.saturation).value = 8f * intensity;
				((VolumeParameter<float>)(object)_color.postExposure).value = (0.04f + Mathf.Sin(time * 0.25f) * 0.03f) * intensity;
				((VolumeParameter<Color>)(object)_split.shadows).value = new Color(0.16f, 0.42f, 0.5f);
				((VolumeParameter<Color>)(object)_split.highlights).value = new Color(0.72f, 0.52f, 0.32f);
				((VolumeParameter<float>)(object)_split.balance).value = 12f;
				((VolumeParameter<float>)(object)_wb.temperature).value = 8f * intensity;
				((VolumeParameter<float>)(object)_wb.tint).value = -3f * intensity;
				((VolumeParameter<float>)(object)_bloom.threshold).value = 1.1f;
				((VolumeParameter<float>)(object)_bloom.intensity).value = 0.45f * intensity;
				((VolumeParameter<float>)(object)_vig.intensity).value = 0.2f * intensity;
				((VolumeParameter<float>)(object)_vig.smoothness).value = 0.6f;
				((VolumeParameter<Color>)(object)_vig.color).value = Color.black;
			}
		}

		public void Disable()
		{
			_on = false;
			if ((Object)(object)_volume != (Object)null)
			{
				_volume.weight = 0f;
				((Component)_volume).gameObject.SetActive(false);
			}
		}

		public void EnsureDisabled()
		{
			if (_on)
			{
				Disable();
			}
		}
	}
	internal enum GradeType
	{
		Realistic,
		Cartoon,
		Whiplash
	}
	internal class GradeEffect
	{
		private readonly GradeType _type;

		private Volume _volume;

		private ColorAdjustments _color;

		private Tonemapping _tone;

		private SplitToning _split;

		private ShadowsMidtonesHighlights _smh;

		private Bloom _bloom;

		private Vignette _vig;

		private WhiteBalance _wb;

		private bool _built;

		private bool _on;

		public GradeEffect(GradeType type)
		{
			_type = type;
		}

		private void Build()
		{
			if (!_built)
			{
				float priority = 1060f + (float)_type * 8f;
				_volume = Rp.MakeGlobalVolume("BonelabShaders_" + _type, priority, out var profile);
				_color = profile.Add<ColorAdjustments>(true);
				_tone = profile.Add<Tonemapping>(true);
				_split = profile.Add<SplitToning>(true);
				_smh = profile.Add<ShadowsMidtonesHighlights>(true);
				_bloom = profile.Add<Bloom>(true);
				_vig = profile.Add<Vignette>(true);
				_wb = profile.Add<WhiteBalance>(true);
				_built = true;
				MelonLogger.Msg("[" + _type.ToString() + "] volume built");
			}
		}

		public void Tick(float intensity)
		{
			//IL_00bc: 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)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_04de: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			Build();
			if (!((Object)(object)_volume == (Object)null))
			{
				if (!_on)
				{
					((Component)_volume).gameObject.SetActive(true);
					_on = true;
				}
				float num = Mathf.Clamp(intensity, 0f, 1.5f);
				_volume.weight = Mathf.Clamp01(num);
				float time = Time.time;
				((VolumeParameter<float>)(object)_color.hueShift).value = 0f;
				((VolumeParameter<float>)(object)_color.saturation).value = 0f;
				((VolumeParameter<float>)(object)_color.contrast).value = 0f;
				((VolumeParameter<float>)(object)_color.postExposure).value = 0f;
				((VolumeParameter<Color>)(object)_color.colorFilter).value = Color.white;
				((VolumeParameter<TonemappingMode>)(object)_tone.mode).value = (TonemappingMode)0;
				((VolumeParameter<Color>)(object)_split.shadows).value = new Color(0.5f, 0.5f, 0.5f);
				((VolumeParameter<Color>)(object)_split.highlights).value = new Color(0.5f, 0.5f, 0.5f);
				((VolumeParameter<float>)(object)_split.balance).value = 0f;
				((VolumeParameter<Vector4>)(object)_smh.shadows).value = new Vector4(1f, 1f, 1f, 0f);
				((VolumeParameter<Vector4>)(object)_smh.midtones).value = new Vector4(1f, 1f, 1f, 0f);
				((VolumeParameter<Vector4>)(object)_smh.highlights).value = new Vector4(1f, 1f, 1f, 0f);
				((VolumeParameter<float>)(object)_bloom.threshold).value = 1.1f;
				((VolumeParameter<float>)(object)_bloom.intensity).value = 0f;
				((VolumeParameter<float>)(object)_vig.intensity).value = 0f;
				((VolumeParameter<Color>)(object)_vig.color).value = Color.black;
				((VolumeParameter<float>)(object)_vig.smoothness).value = 0.5f;
				((VolumeParameter<float>)(object)_wb.temperature).value = 0f;
				((VolumeParameter<float>)(object)_wb.tint).value = 0f;
				switch (_type)
				{
				case GradeType.Realistic:
					RenderScaleControl.Set(1.25f, (UpscalingFilterSelection)0);
					((VolumeParameter<TonemappingMode>)(object)_tone.mode).value = (TonemappingMode)2;
					((VolumeParameter<float>)(object)_color.contrast).value = 14f * num;
					((VolumeParameter<float>)(object)_color.saturation).value = 6f * num;
					((VolumeParameter<float>)(object)_color.postExposure).value = 0.03f * num;
					((VolumeParameter<Vector4>)(object)_smh.shadows).value = new Vector4(0.92f, 0.97f, 1.12f, 0f);
					((VolumeParameter<Vector4>)(object)_smh.highlights).value = new Vector4(1.12f, 1.03f, 0.88f, 0f);
					((VolumeParameter<float>)(object)_smh.shadowsEnd).value = 0.3f;
					((VolumeParameter<float>)(object)_smh.highlightsStart).value = 0.55f;
					((VolumeParameter<float>)(object)_bloom.threshold).value = 1.05f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = 0.5f * num;
					((VolumeParameter<float>)(object)_bloom.scatter).value = 0.6f;
					((VolumeParameter<float>)(object)_vig.intensity).value = 0.15f * num;
					((VolumeParameter<float>)(object)_vig.smoothness).value = 0.7f;
					((VolumeParameter<float>)(object)_wb.temperature).value = 4f * num;
					break;
				case GradeType.Cartoon:
					((VolumeParameter<TonemappingMode>)(object)_tone.mode).value = (TonemappingMode)0;
					((VolumeParameter<float>)(object)_color.saturation).value = 60f * num;
					((VolumeParameter<float>)(object)_color.contrast).value = 38f * num;
					((VolumeParameter<float>)(object)_color.postExposure).value = 0.05f * num;
					((VolumeParameter<Vector4>)(object)_smh.midtones).value = new Vector4(1.05f, 1.05f, 1.05f, 0f);
					((VolumeParameter<float>)(object)_bloom.threshold).value = 1f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = 0.3f * num;
					break;
				case GradeType.Whiplash:
					((VolumeParameter<TonemappingMode>)(object)_tone.mode).value = (TonemappingMode)2;
					((VolumeParameter<float>)(object)_color.contrast).value = 18f * num;
					((VolumeParameter<float>)(object)_color.saturation).value = -6f * num;
					((VolumeParameter<float>)(object)_color.postExposure).value = (-0.05f + Mathf.Sin(time * 8f) * 0.02f) * num;
					((VolumeParameter<Color>)(object)_color.colorFilter).value = Color.Lerp(Color.white, new Color(1f, 0.82f, 0.5f), Mathf.Clamp01(num));
					((VolumeParameter<Color>)(object)_split.shadows).value = new Color(0.4f, 0.3f, 0.16f);
					((VolumeParameter<Color>)(object)_split.highlights).value = new Color(0.85f, 0.68f, 0.35f);
					((VolumeParameter<float>)(object)_split.balance).value = 15f;
					((VolumeParameter<float>)(object)_wb.temperature).value = 26f * num;
					((VolumeParameter<float>)(object)_wb.tint).value = 4f * num;
					((VolumeParameter<float>)(object)_vig.intensity).value = 0.3f * num;
					((VolumeParameter<float>)(object)_vig.smoothness).value = 0.5f;
					((VolumeParameter<float>)(object)_bloom.threshold).value = 1f;
					((VolumeParameter<float>)(object)_bloom.intensity).value = 0.4f * num;
					break;
				}
			}
		}

		public void Disable()
		{
			_on = false;
			if ((Object)(object)_volume != (Object)null)
			{
				_volume.weight = 0f;
				((Component)_volume).gameObject.SetActive(false);
			}
			if (_type == GradeType.Realistic)
			{
				RenderScaleControl.Restore();
			}
		}

		public void EnsureDisabled()
		{
			if (_on)
			{
				Disable();
			}
		}
	}
	public class ShadersMod : MelonMod
	{
		public const string Version = "3.0.0";

		private static MelonPreferences_Category _prefs;

		private static MelonPreferences_Entry<bool> _acidEnabled;

		private static MelonPreferences_Entry<int> _acidStyle;

		private static MelonPreferences_Entry<float> _acidIntensity;

		private static MelonPreferences_Entry<float> _acidSpeed;

		private static MelonPreferences_Entry<bool> _pixelEnabled;

		private static MelonPreferences_Entry<float> _pixelSize;

		private static MelonPreferences_Entry<int> _pixelPalette;

		private static MelonPreferences_Entry<bool> _bodycamEnabled;

		private static MelonPreferences_Entry<float> _bodycamIntensity;

		private static MelonPreferences_Entry<bool> _bodycamRec;

		private static MelonPreferences_Entry<bool> _cineEnabled;

		private static MelonPreferences_Entry<float> _cineIntensity;

		private static MelonPreferences_Entry<bool> _realEnabled;

		private static MelonPreferences_Entry<float> _realIntensity;

		private static MelonPreferences_Entry<bool> _cartoonEnabled;

		private static MelonPreferences_Entry<float> _cartoonIntensity;

		private static MelonPreferences_Entry<bool> _whipEnabled;

		private static MelonPreferences_Entry<float> _whipIntensity;

		private static AcidStyle _acidStyleVal;

		private static PixelPalette _pixelPaletteVal;

		private static BoolElement _acidToggle;

		private static BoolElement _pixelToggle;

		private static BoolElement _bodycamToggle;

		private static BoolElement _cineToggle;

		private static FloatElement _acidIntensityEl;

		private static FloatElement _acidSpeedEl;

		private static FloatElement _pixelSizeEl;

		private static FloatElement _bodycamIntEl;

		private static FloatElement _cineIntEl;

		private static EnumElement _acidStyleEl;

		private static EnumElement _pixelPaletteEl;

		private static BoolElement _bodycamRecEl;

		private static BoolElement _realToggle;

		private static BoolElement _cartoonToggle;

		private static BoolElement _whipToggle;

		private static FloatElement _realIntEl;

		private static FloatElement _cartoonIntEl;

		private static FloatElement _whipIntEl;

		private static readonly AcidEffect Acid = new AcidEffect();

		private static readonly PixelEffect Pixel = new PixelEffect();

		private static readonly BodycamEffect Bodycam = new BodycamEffect();

		private static readonly CinematicEffect Cinematic = new CinematicEffect();

		private static readonly GradeEffect Realistic = new GradeEffect(GradeType.Realistic);

		private static readonly GradeEffect Cartoon = new GradeEffect(GradeType.Cartoon);

		private static readonly GradeEffect Whiplash = new GradeEffect(GradeType.Whiplash);

		private static Camera _cam;

		private static bool _prefsReady;

		private static string _bundlePath;

		private static bool _depthTried;

		private static int _initFrames;

		public override void OnInitializeMelon()
		{
			SetupPrefs();
			_bundlePath = Path.Combine(Path.GetDirectoryName(Application.dataPath), "UserData", "BonelabShaders", "bonelabshaders");
			SetupMenu();
			((MelonBase)this).LoggerInstance.Msg("Bonelab Shaders v3.0.0 loaded.");
		}

		private static void SetupPrefs()
		{
			_prefs = MelonPreferences.CreateCategory("BonelabShaders");
			_acidEnabled = _prefs.CreateEntry<bool>("AcidEnabled", false, "Acid Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_acidStyle = _prefs.CreateEntry<int>("AcidStyle", 0, "Acid Style", (string)null, false, false, (ValueValidator)null, (string)null);
			_acidIntensity = _prefs.CreateEntry<float>("AcidIntensity", 0.9f, "Acid Intensity", (string)null, false, false, (ValueValidator)null, (string)null);
			_acidSpeed = _prefs.CreateEntry<float>("AcidSpeed", 1f, "Acid Speed", (string)null, false, false, (ValueValidator)null, (string)null);
			_pixelEnabled = _prefs.CreateEntry<bool>("PixelEnabled", false, "Pixel Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_pixelSize = _prefs.CreateEntry<float>("PixelSize", 6f, "Pixel Size", (string)null, false, false, (ValueValidator)null, (string)null);
			_pixelPalette = _prefs.CreateEntry<int>("PixelPalette", 1, "Pixel Palette", (string)null, false, false, (ValueValidator)null, (string)null);
			_bodycamEnabled = _prefs.CreateEntry<bool>("BodycamEnabled", false, "Bodycam Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_bodycamIntensity = _prefs.CreateEntry<float>("BodycamIntensity", 1f, "Bodycam Intensity", (string)null, false, false, (ValueValidator)null, (string)null);
			_bodycamRec = _prefs.CreateEntry<bool>("BodycamRec", true, "Bodycam REC UI", (string)null, false, false, (ValueValidator)null, (string)null);
			_cineEnabled = _prefs.CreateEntry<bool>("CinematicEnabled", false, "Cinematic Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_cineIntensity = _prefs.CreateEntry<float>("CinematicIntensity", 1f, "Cinematic Intensity", (string)null, false, false, (ValueValidator)null, (string)null);
			_realEnabled = _prefs.CreateEntry<bool>("RealisticEnabled", false, "Realistic Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_realIntensity = _prefs.CreateEntry<float>("RealisticIntensity", 1f, "Realistic Intensity", (string)null, false, false, (ValueValidator)null, (string)null);
			_cartoonEnabled = _prefs.CreateEntry<bool>("CartoonEnabled", false, "Cartoon Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_cartoonIntensity = _prefs.CreateEntry<float>("CartoonIntensity", 1f, "Cartoon Intensity", (string)null, false, false, (ValueValidator)null, (string)null);
			_whipEnabled = _prefs.CreateEntry<bool>("WhiplashEnabled", false, "Whiplash Enabled", (string)null, false, false, (ValueValidator)null, (string)null);
			_whipIntensity = _prefs.CreateEntry<float>("WhiplashIntensity", 1f, "Whiplash Intensity", (string)null, false, false, (ValueValidator)null, (string)null);
			_acidStyleVal = (AcidStyle)_acidStyle.Value;
			_pixelPaletteVal = (PixelPalette)_pixelPalette.Value;
			_prefsReady = true;
		}

		private void SetupMenu()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: 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)
			//IL_01c0: 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_0268: 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_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0304: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0552: Unknown result type (might be due to invalid IL or missing references)
			//IL_0564: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
			Page obj = Page.Root.CreatePage("Shaders", Color.magenta, 0, true);
			Page obj2 = obj.CreatePage("Acid", new Color(0.6f, 1f, 0.2f), 0, true);
			_acidToggle = obj2.CreateBool("Enabled", Color.green, _acidEnabled.Value, (Action<bool>)delegate(bool v)
			{
				_acidEnabled.Value = v;
				Save();
				if (!v)
				{
					Acid.Disable();
				}
			});
			_acidStyleEl = obj2.CreateEnum("Style", new Color(0.8f, 0.4f, 1f), (Enum)_acidStyleVal, (Action<Enum>)delegate(Enum e)
			{
				_acidStyleVal = (AcidStyle)(object)e;
				_acidStyle.Value = (int)_acidStyleVal;
				Save();
			});
			_acidIntensityEl = obj2.CreateFloat("Intensity", Color.white, _acidIntensity.Value, 0.1f, 0f, 2f, (Action<float>)delegate(float v)
			{
				_acidIntensity.Value = v;
				Save();
			});
			_acidSpeedEl = obj2.CreateFloat("Speed", Color.white, _acidSpeed.Value, 0.1f, 0.1f, 3f, (Action<float>)delegate(float v)
			{
				_acidSpeed.Value = v;
				Save();
			});
			Page obj3 = obj.CreatePage("Pixel", new Color(0.9f, 0.4f, 0.1f), 0, true);
			_pixelToggle = obj3.CreateBool("Enabled", Color.green, _pixelEnabled.Value, (Action<bool>)delegate(bool v)
			{
				_pixelEnabled.Value = v;
				Save();
				if (!v)
				{
					Pixel.Disable();
				}
			});
			_pixelSizeEl = obj3.CreateFloat("Pixel Size", Color.white, _pixelSize.Value, 1f, 2f, 24f, (Action<float>)delegate(float v)
			{
				_pixelSize.Value = v;
				Save();
			});
			_pixelPaletteEl = obj3.CreateEnum("Palette", new Color(1f, 0.8f, 0.3f), (Enum)_pixelPaletteVal, (Action<Enum>)delegate(Enum e)
			{
				_pixelPaletteVal = (PixelPalette)(object)e;
				_pixelPalette.Value = (int)_pixelPaletteVal;
				Save();
			});
			Page obj4 = obj.CreatePage("Bodycam", new Color(0.2f, 0.9f, 0.3f), 0, true);
			_bodycamToggle = obj4.CreateBool("Enabled", Color.green, _bodycamEnabled.Value, (Action<bool>)delegate(bool v)
			{
				_bodycamEnabled.Value = v;
				Save();
				if (!v)
				{
					Bodycam.Disable();
				}
			});
			_bodycamIntEl = obj4.CreateFloat("Intensity", Color.white, _bodycamIntensity.Value, 0.1f, 0f, 1.5f, (Action<float>)delegate(float v)
			{
				_bodycamIntensity.Value = v;
				Save();
			});
			_bodycamRecEl = obj4.CreateBool("REC Overlay", Color.red, _bodycamRec.Value, (Action<bool>)delegate(bool v)
			{
				_bodycamRec.Value = v;
				Save();
			});
			Page obj5 = obj.CreatePage("Cinematic", new Color(1f, 0.85f, 0.4f), 0, true);
			_cineToggle = obj5.CreateBool("Enabled", Color.green, _cineEnabled.Value, (Action<bool>)delegate(bool v)
			{
				_cineEnabled.Value = v;
				Save();
				if (!v)
				{
					Cinematic.Disable();
				}
			});
			_cineIntEl = obj5.CreateFloat("Intensity", Color.white, _cineIntensity.Value, 0.1f, 0f, 1.5f, (Action<float>)delegate(float v)
			{
				_cineIntensity.Value = v;
				Save();
			});
			Page obj6 = obj.CreatePage("Realistic", new Color(0.5f, 0.7f, 1f), 0, true);
			_realToggle = obj6.CreateBool("Enabled", Color.green, _realEnabled.Value, (Action<bool>)delegate(bool v)
			{
				_realEnabled.Value = v;
				Save();
				if (!v)
				{
					Realistic.Disable();
				}
			});
			_realIntEl = obj6.CreateFloat("Intensity", Color.white, _realIntensity.Value, 0.1f, 0f, 1.5f, (Action<float>)delegate(float v)
			{
				_realIntensity.Value = v;
				Save();
			});
			Page obj7 = obj.CreatePage("Cartoon", new Color(1f, 0.3f, 0.6f), 0, true);
			_cartoonToggle = obj7.CreateBool("Enabled", Color.green, _cartoonEnabled.Value, (Action<bool>)delegate(bool v)
			{
				_cartoonEnabled.Value = v;
				Save();
				if (!v)
				{
					Cartoon.Disable();
				}
			});
			_cartoonIntEl = obj7.CreateFloat("Intensity", Color.white, _cartoonIntensity.Value, 0.1f, 0f, 1.5f, (Action<float>)delegate(float v)
			{
				_cartoonIntensity.Value = v;
				Save();
			});
			Page obj8 = obj.CreatePage("Whiplash", new Color(1f, 0.75f, 0.1f), 0, true);
			_whipToggle = obj8.CreateBool("Enabled", Color.green, _whipEnabled.Value, (Action<bool>)delegate(bool v)
			{
				_whipEnabled.Value = v;
				Save();
				if (!v)
				{
					Whiplash.Disable();
				}
			});
			_whipIntEl = obj8.CreateFloat("Intensity", Color.white, _whipIntensity.Value, 0.1f, 0f, 1.5f, (Action<float>)delegate(float v)
			{
				_whipIntensity.Value = v;
				Save();
			});
			obj.CreateFunction("Turn Everything Off", Color.red, (Action)delegate
			{
				_acidEnabled.Value = false;
				_pixelEnabled.Value = false;
				_bodycamEnabled.Value = false;
				_cineEnabled.Value = false;
				_realEnabled.Value = false;
				_cartoonEnabled.Value = false;
				_whipEnabled.Value = false;
				Save();
				Acid.Disable();
				Pixel.Disable();
				Bodycam.Disable();
				Cinematic.Disable();
				Realistic.Disable();
				Cartoon.Disable();
				Whiplash.Disable();
				SyncMenu();
			});
		}

		private static void Save()
		{
			if (_prefs != null)
			{
				_prefs.SaveToFile(false);
			}
		}

		public override void OnPreferencesLoaded()
		{
			if (_prefsReady)
			{
				_acidStyleVal = (AcidStyle)_acidStyle.Value;
				_pixelPaletteVal = (PixelPalette)_pixelPalette.Value;
				SyncMenu();
			}
		}

		private static void SyncMenu()
		{
			if (_acidToggle != null)
			{
				_acidToggle.Value = _acidEnabled.Value;
			}
			if (_acidStyleEl != null)
			{
				_acidStyleEl.Value = _acidStyleVal;
			}
			if (_acidIntensityEl != null)
			{
				_acidIntensityEl.Value = _acidIntensity.Value;
			}
			if (_acidSpeedEl != null)
			{
				_acidSpeedEl.Value = _acidSpeed.Value;
			}
			if (_pixelToggle != null)
			{
				_pixelToggle.Value = _pixelEnabled.Value;
			}
			if (_pixelSizeEl != null)
			{
				_pixelSizeEl.Value = _pixelSize.Value;
			}
			if (_pixelPaletteEl != null)
			{
				_pixelPaletteEl.Value = _pixelPaletteVal;
			}
			if (_bodycamToggle != null)
			{
				_bodycamToggle.Value = _bodycamEnabled.Value;
			}
			if (_bodycamIntEl != null)
			{
				_bodycamIntEl.Value = _bodycamIntensity.Value;
			}
			if (_bodycamRecEl != null)
			{
				_bodycamRecEl.Value = _bodycamRec.Value;
			}
			if (_cineToggle != null)
			{
				_cineToggle.Value = _cineEnabled.Value;
			}
			if (_cineIntEl != null)
			{
				_cineIntEl.Value = _cineIntensity.Value;
			}
			if (_realToggle != null)
			{
				_realToggle.Value = _realEnabled.Value;
			}
			if (_realIntEl != null)
			{
				_realIntEl.Value = _realIntensity.Value;
			}
			if (_cartoonToggle != null)
			{
				_cartoonToggle.Value = _cartoonEnabled.Value;
			}
			if (_cartoonIntEl != null)
			{
				_cartoonIntEl.Value = _cartoonIntensity.Value;
			}
			if (_whipToggle != null)
			{
				_whipToggle.Value = _whipEnabled.Value;
			}
			if (_whipIntEl != null)
			{
				_whipIntEl.Value = _whipIntensity.Value;
			}
		}

		private static Camera FindCam()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Invalid comparison between Unknown and I4
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Invalid comparison between Unknown and I4
			if ((Object)(object)_cam != (Object)null)
			{
				return _cam;
			}
			Camera val = Camera.main;
			if ((Object)(object)val == (Object)null)
			{
				Il2CppReferenceArray<Camera> allCameras = Camera.allCameras;
				foreach (Camera item in (Il2CppArrayBase<Camera>)(object)allCameras)
				{
					if ((Object)(object)item != (Object)null && (int)item.cameraType == 1 && item.stereoEnabled)
					{
						val = item;
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					foreach (Camera item2 in (Il2CppArrayBase<Camera>)(object)allCameras)
					{
						if ((Object)(object)item2 != (Object)null && (int)item2.cameraType == 1)
						{
							val = item2;
							break;
						}
					}
				}
			}
			_cam = val;
			return val;
		}

		private void TryInitDepth()
		{
			if (!_depthTried && ++_initFrames >= 300)
			{
				_depthTried = true;
				DepthShaders.Init(_bundlePath, ((MelonBase)this).HarmonyInstance);
			}
		}

		public override void OnUpdate()
		{
			if (!_prefsReady)
			{
				return;
			}
			TryInitDepth();
			if (_acidEnabled.Value)
			{
				Acid.Tick(_acidStyleVal, _acidIntensity.Value, _acidSpeed.Value);
			}
			else
			{
				Acid.EnsureDisabled();
			}
			if (_pixelEnabled.Value)
			{
				Pixel.EnsureApplied(_pixelSize.Value, _pixelPaletteVal);
			}
			else
			{
				Pixel.Disable();
			}
			Camera val = ((_bodycamEnabled.Value && _bodycamRec.Value) ? FindCam() : null);
			if (_bodycamEnabled.Value)
			{
				Bodycam.Tick(_bodycamIntensity.Value);
				if ((Object)(object)val != (Object)null)
				{
					Bodycam.UpdateHud(((Component)val).transform, _bodycamRec.Value);
				}
			}
			else
			{
				Bodycam.EnsureDisabled();
			}
			if (_cineEnabled.Value)
			{
				Cinematic.Tick(_cineIntensity.Value);
			}
			else
			{
				Cinematic.EnsureDisabled();
			}
			if (_realEnabled.Value)
			{
				Realistic.Tick(_realIntensity.Value);
			}
			else
			{
				Realistic.EnsureDisabled();
			}
			if (_cartoonEnabled.Value)
			{
				Cartoon.Tick(_cartoonIntensity.Value);
			}
			else
			{
				Cartoon.EnsureDisabled();
			}
			if (_whipEnabled.Value)
			{
				Whiplash.Tick(_whipIntensity.Value);
			}
			else
			{
				Whiplash.EnsureDisabled();
			}
		}
	}
}