Decompiled source of Fullbright Toggle v1.1.0

mod/fullbright.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using NicebudArmMod;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(FullbrightToggle), "Fullbright Toggle", "1.0.0", "Nicebud", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("armstretch")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("armstretch")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8499ef9c-7a39-4309-88a0-ab764a503be2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace NicebudArmMod;

public class FullbrightToggle : MelonMod
{
	private struct OriginalLightData
	{
		public float Intensity;

		public LightShadows Shadows;
	}

	private Dictionary<Light, OriginalLightData> _originalLights = new Dictionary<Light, OriginalLightData>();

	private float _originalAmbientIntensity;

	private Color _originalAmbientColor;

	private AmbientMode _originalAmbientMode;

	private bool _originalFog;

	private bool _fullbrightEnabled;

	private object _rescanRoutine;

	private Light _syntheticSun;

	public override void OnInitializeMelon()
	{
		SetupBoneMenu();
	}

	private void SetupBoneMenu()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		Page.Root.CreatePage("Nicebud", Color.white, 0, true).CreatePage("Fullbright Toggle", Color.yellow, 0, true).CreateBool("Fullbright", Color.green, _fullbrightEnabled, (Action<bool>)delegate(bool value)
		{
			_fullbrightEnabled = value;
			if (_fullbrightEnabled)
			{
				EnableFullbright();
			}
			else
			{
				DisableFullbright();
			}
		});
	}

	private void EnableFullbright()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Expected O, but got Unknown
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		_originalAmbientIntensity = RenderSettings.ambientIntensity;
		_originalAmbientColor = RenderSettings.ambientLight;
		_originalAmbientMode = RenderSettings.ambientMode;
		_originalFog = RenderSettings.fog;
		RenderSettings.ambientMode = (AmbientMode)3;
		RenderSettings.ambientLight = Color.white;
		RenderSettings.ambientIntensity = 2.5f;
		RenderSettings.fog = false;
		ScanAndBoostLights();
		if ((Object)(object)_syntheticSun == (Object)null)
		{
			GameObject val = new GameObject("Fullbright_SyntheticSun");
			_syntheticSun = val.AddComponent<Light>();
			_syntheticSun.type = (LightType)1;
			_syntheticSun.intensity = 2.5f;
			_syntheticSun.shadows = (LightShadows)0;
			_syntheticSun.color = Color.white;
			val.transform.rotation = Quaternion.Euler(50f, -30f, 0f);
		}
		else
		{
			((Component)_syntheticSun).gameObject.SetActive(true);
		}
		if (_rescanRoutine == null)
		{
			_rescanRoutine = MelonCoroutines.Start(RescanLoop());
		}
	}

	private IEnumerator RescanLoop()
	{
		while (_fullbrightEnabled)
		{
			ScanAndBoostLights();
			yield return (object)new WaitForSeconds(2f);
		}
		_rescanRoutine = null;
	}

	private void ScanAndBoostLights()
	{
		//IL_0030: 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_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Light[] array = Il2CppArrayBase<Light>.op_Implicit(Resources.FindObjectsOfTypeAll<Light>());
		foreach (Light val in array)
		{
			if (!((Object)(object)val == (Object)null) && !_originalLights.ContainsKey(val))
			{
				Scene scene = ((Component)val).gameObject.scene;
				if (((Scene)(ref scene)).IsValid())
				{
					_originalLights[val] = new OriginalLightData
					{
						Intensity = val.intensity,
						Shadows = val.shadows
					};
					val.intensity = 3f;
					val.shadows = (LightShadows)0;
				}
			}
		}
	}

	private void DisableFullbright()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
		if (_rescanRoutine != null)
		{
			MelonCoroutines.Stop(_rescanRoutine);
			_rescanRoutine = null;
		}
		foreach (KeyValuePair<Light, OriginalLightData> originalLight in _originalLights)
		{
			Light key = originalLight.Key;
			if (!((Object)key == (Object)null))
			{
				key.intensity = originalLight.Value.Intensity;
				key.shadows = originalLight.Value.Shadows;
			}
		}
		_originalLights.Clear();
		if ((Object)(object)_syntheticSun != (Object)null)
		{
			((Component)_syntheticSun).gameObject.SetActive(false);
		}
		RenderSettings.ambientMode = _originalAmbientMode;
		RenderSettings.ambientLight = _originalAmbientColor;
		RenderSettings.ambientIntensity = _originalAmbientIntensity;
		RenderSettings.fog = _originalFog;
	}

	public override void OnSceneWasLoaded(int buildIndex, string sceneName)
	{
		if (_fullbrightEnabled)
		{
			EnableFullbright();
		}
	}

	public override void OnDeinitializeMelon()
	{
		if (_fullbrightEnabled)
		{
			DisableFullbright();
		}
	}
}