Decompiled source of NoBloom v1.2.0

Mods/NoBloom.dll

Decompiled 13 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppKeepsake.Options;
using Il2CppMK.Glow.HDRP;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using Il2CppTMPro;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using NoBloom;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(NoBloomMod), "NoBloom", "1.2.0", "Isaac", null)]
[assembly: MelonGame(null, null)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NoBloom")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("NoBloom")]
[assembly: AssemblyTitle("NoBloom")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 NoBloom
{
	public class NoBloomMod : MelonMod
	{
		internal static bool DisableBloom = true;

		private MelonPreferences_Entry<bool> _disableEntry;

		private MelonPreferences_Entry<string> _toggleKey;

		private float _nextScan;

		internal static Instance Log;

		private static MelonPreferences_Entry<bool> _entry;

		public override void OnInitializeMelon()
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			MelonPreferences_Category val = MelonPreferences.CreateCategory("NoBloom");
			_disableEntry = val.CreateEntry<bool>("DisableBloom", true, "Disable bloom (true = bloom off)", (string)null, false, false, (ValueValidator)null, (string)null);
			_toggleKey = val.CreateEntry<string>("ToggleKey", "F9", "Key to toggle bloom at runtime (UnityEngine.KeyCode name, or 'None')", (string)null, false, false, (ValueValidator)null, (string)null);
			DisableBloom = _disableEntry.Value;
			Log = ((MelonBase)this).LoggerInstance;
			_entry = _disableEntry;
			try
			{
				MethodInfo method = typeof(MKGlow).GetMethod("IsActive", BindingFlags.Instance | BindingFlags.Public);
				MethodInfo method2 = typeof(NoBloomMod).GetMethod("IsActivePostfix", BindingFlags.Static | BindingFlags.NonPublic);
				((MelonBase)this).HarmonyInstance.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((MelonBase)this).LoggerInstance.Msg("Patched MKGlow.IsActive");
			}
			catch (Exception ex)
			{
				((MelonBase)this).LoggerInstance.Error("Failed to patch MKGlow.IsActive: " + ex);
			}
			try
			{
				MethodInfo method3 = typeof(GUI_VideoSettings).GetMethod("Start", BindingFlags.Instance | BindingFlags.Public);
				((MelonBase)this).HarmonyInstance.Patch((MethodBase)method3, (HarmonyMethod)null, new HarmonyMethod(typeof(NoBloomMod).GetMethod("VideoStartPostfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((MelonBase)this).LoggerInstance.Msg("Patched GUI_VideoSettings.Start");
			}
			catch (Exception ex2)
			{
				((MelonBase)this).LoggerInstance.Error("Settings menu patch failed: " + ex2);
			}
			((MelonBase)this).LoggerInstance.Msg("NoBloom loaded. Bloom disabled: " + DisableBloom);
		}

		private static void VideoStartPostfix(GUI_VideoSettings __instance)
		{
			try
			{
				InjectToggle(__instance);
			}
			catch (Exception ex)
			{
				Instance log = Log;
				if (log != null)
				{
					log.Error("Failed to add Bloom toggle: " + ex);
				}
			}
		}

		private static void InjectToggle(GUI_VideoSettings page)
		{
			Transform val = ((Component)page).transform.Find("ScrollView/VBox");
			if ((Object)(object)val == (Object)null)
			{
				Instance log = Log;
				if (log != null)
				{
					log.Warning("Video settings VBox not found");
				}
			}
			else
			{
				if ((Object)(object)val.Find("NoBloom_Toggle") != (Object)null)
				{
					return;
				}
				Transform val2 = val.Find("ShowFPSDisplay") ?? val.Find("EnableVSync");
				if ((Object)(object)val2 == (Object)null)
				{
					Instance log2 = Log;
					if (log2 != null)
					{
						log2.Warning("No template toggle found");
					}
					return;
				}
				GameObject val3 = Object.Instantiate<GameObject>(((Component)val2).gameObject, val);
				((Object)val3).name = "NoBloom_Toggle";
				val3.SetActive(true);
				foreach (Component component3 in val3.GetComponents<Component>())
				{
					if (!((Object)(object)component3 == (Object)null))
					{
						string name = ((MemberInfo)((Object)component3).GetIl2CppType()).Name;
						if (name == "LocalizeStringEvent" || name == "GUI_OptionResetter")
						{
							Object.Destroy((Object)(object)component3);
						}
					}
				}
				Transform val4 = val3.transform.Find("Label");
				if ((Object)(object)val4 != (Object)null)
				{
					TextMeshProUGUI component = ((Component)val4).GetComponent<TextMeshProUGUI>();
					if ((Object)(object)component != (Object)null)
					{
						((TMP_Text)component).text = "Bloom";
					}
				}
				Toggle component2 = val3.GetComponent<Toggle>();
				((UnityEventBase)component2.onValueChanged).m_PersistentCalls.Clear();
				((UnityEventBase)component2.onValueChanged).RemoveAllListeners();
				component2.SetIsOnWithoutNotify(!DisableBloom);
				((UnityEvent<bool>)(object)component2.onValueChanged).AddListener(UnityAction<bool>.op_Implicit((Action<bool>)OnBloomToggled));
				val3.transform.SetSiblingIndex(val2.GetSiblingIndex());
				Instance log3 = Log;
				if (log3 != null)
				{
					log3.Msg("Added Bloom toggle to Graphics settings");
				}
			}
		}

		private static void OnBloomToggled(bool bloomOn)
		{
			DisableBloom = !bloomOn;
			if (_entry != null)
			{
				_entry.Value = DisableBloom;
			}
			MelonPreferences.Save();
			Instance log = Log;
			if (log != null)
			{
				log.Msg("Bloom " + (bloomOn ? "enabled" : "disabled") + " via settings menu");
			}
		}

		private static void IsActivePostfix(ref bool __result)
		{
			if (DisableBloom)
			{
				__result = false;
			}
		}

		public override void OnUpdate()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (Enum.TryParse<KeyCode>(_toggleKey.Value, ignoreCase: true, out KeyCode result) && (int)result != 0 && Input.GetKeyDown(result))
				{
					DisableBloom = !DisableBloom;
					_disableEntry.Value = DisableBloom;
					((MelonBase)this).LoggerInstance.Msg("Bloom " + (DisableBloom ? "disabled" : "enabled"));
				}
			}
			catch
			{
			}
		}
	}
}