Decompiled source of Clear UI v0.2.0

ClearUI.dll

Decompiled 3 weeks ago
using System;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering.PostProcessing;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ClearUI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("ClearUI")]
[assembly: AssemblyTitle("ClearUI")]
[assembly: AssemblyVersion("0.2.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace ClearUI
{
	[BepInPlugin("soundedsquash.clearui", "Clear UI", "0.2.0.0")]
	public class PluginBase : BaseUnityPlugin
	{
		private const string PluginGuid = "soundedsquash.clearui";

		private const string PluginName = "Clear UI";

		private const string PluginVersion = "0.2.0.0";

		private readonly Harmony _harmony = new Harmony("soundedsquash.clearui");

		private static readonly ManualLogSource ManualLogSource = Logger.CreateLogSource("soundedsquash.clearui");

		public void Awake()
		{
			Settings.Initialize(((BaseUnityPlugin)this).Config, ManualLogSource);
			_harmony.PatchAll();
			ManualLogSource.LogInfo((object)"Clear UI loaded");
		}
	}
	public static class Settings
	{
		public static ConfigEntry<bool> ChromaticAberrationEnabled { get; set; }

		public static ConfigEntry<bool> LensDistortionEnabled { get; set; }

		public static ConfigEntry<bool> BloomEnabled { get; set; }

		public static ManualLogSource Logger { get; private set; }

		private static List<PostProcessEffectSettings>? PostProcessEffectSettingsList
		{
			get
			{
				GameObject obj = GameObject.Find("Game Director/Post Processing/Post Processing Overlay");
				if (obj == null)
				{
					return null;
				}
				PostProcessVolume component = obj.GetComponent<PostProcessVolume>();
				if (component == null)
				{
					return null;
				}
				return component.profile?.settings;
			}
		}

		internal static void Initialize(ConfigFile config, ManualLogSource logger)
		{
			Logger = logger;
			(ChromaticAberrationEnabled = config.Bind<bool>("General", "Chromatic Aberration", false, "Color distortion around the edges of the screen")).SettingChanged += OnConfigChanged;
			(BloomEnabled = config.Bind<bool>("General", "Bloom", false, "Glow")).SettingChanged += OnConfigChanged;
			(LensDistortionEnabled = config.Bind<bool>("General", "Lens Distortion", false, "Curved screen")).SettingChanged += OnConfigChanged;
		}

		private static void OnConfigChanged(object sender, EventArgs e)
		{
			Logger.LogDebug((object)"Settings updated. Refreshing post process effects.");
			RefreshPostProcessEffects();
		}

		public static void RefreshPostProcessEffects()
		{
			List<PostProcessEffectSettings> postProcessEffectSettingsList = PostProcessEffectSettingsList;
			if (postProcessEffectSettingsList == null)
			{
				return;
			}
			foreach (PostProcessEffectSettings item in postProcessEffectSettingsList)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				Bloom val = (Bloom)(object)((item is Bloom) ? item : null);
				if (val == null)
				{
					ChromaticAberration val2 = (ChromaticAberration)(object)((item is ChromaticAberration) ? item : null);
					if (val2 == null)
					{
						LensDistortion val3 = (LensDistortion)(object)((item is LensDistortion) ? item : null);
						if (val3 != null)
						{
							((PostProcessEffectSettings)val3).active = LensDistortionEnabled.Value;
						}
					}
					else
					{
						((PostProcessEffectSettings)val2).active = ChromaticAberrationEnabled.Value;
					}
				}
				else
				{
					((PostProcessEffectSettings)val).active = BloomEnabled.Value;
				}
			}
		}
	}
}
namespace ClearUI.Patches
{
	[HarmonyPatch(typeof(HUDCanvas))]
	public static class HUDCanvasPatches
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void HUDCanvasAwakePostfix()
		{
			Settings.RefreshPostProcessEffects();
		}
	}
}