Decompiled source of FullBright v1.0.0

Fullbright.dll

Decompiled 5 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Fullbright")]
[assembly: AssemblyTitle("Fullbright")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 EmpressMods.REPOFullbright
{
	[BepInPlugin("com.empress.repo.fullbright", "Empress Fullbright", "1.2.1")]
	public class EmpressFullbrightPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.empress.repo.fullbright";

		public const string PluginName = "Empress Fullbright";

		public const string PluginVersion = "1.2.1";

		internal static EmpressFullbrightPlugin Instance;

		internal static ManualLogSource Log;

		internal static bool Enabled;

		private static Harmony _harmony;

		private ConfigEntry<KeyboardShortcut> _toggleKey;

		internal ConfigEntry<bool> _disableFog;

		private ConfigEntry<bool> _debugLog;

		private CameraHook _cameraHook;

		private float _nextToggleTime;

		private const float AMBIENT_BOOST = 1.5f;

		private void Awake()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger ?? Logger.CreateLogSource("com.empress.repo.fullbright");
			_toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)120, Array.Empty<KeyCode>()), "Hotkey to toggle Fullbright ON/OFF.");
			_disableFog = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableFog", true, "Turn off/override fog while Fullbright is enabled.");
			_debugLog = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "VerboseLogging", false, "If true, logs keypress detection and state toggles.");
			_cameraHook = new GameObject("EmpressFullbrightCameraHook").AddComponent<CameraHook>();
			Object.DontDestroyOnLoad((Object)(object)((Component)_cameraHook).gameObject);
			_cameraHook.SyncFromConfig(this);
			Enabled = true;
			_harmony = new Harmony("com.empress.repo.fullbright");
			_harmony.PatchAll();
			Log.LogInfo((object)string.Format("{0} {1} loaded. Press {2} to toggle. Fullbright ON by default.", "Empress Fullbright", "1.2.1", _toggleKey.Value));
		}

		private void OnDestroy()
		{
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
			if (Object.op_Implicit((Object)(object)_cameraHook))
			{
				Object.Destroy((Object)(object)((Component)_cameraHook).gameObject);
			}
		}

		private void Update()
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				KeyboardShortcut value = _toggleKey.Value;
				if ((!((KeyboardShortcut)(ref value)).IsDown() && !Input.GetKeyDown((KeyCode)120)) || !(Time.unscaledTime >= _nextToggleTime))
				{
					return;
				}
				_nextToggleTime = Time.unscaledTime + 0.3f;
				Enabled = !Enabled;
				if (!Enabled)
				{
					_cameraHook.RestoreGlobals();
				}
				if (_debugLog.Value)
				{
					ManualLogSource log = Log;
					if (log != null)
					{
						log.LogInfo((object)("Fullbright toggled => " + (Enabled ? "ON" : "OFF")));
					}
				}
			}
			catch
			{
			}
		}

		internal float GetAmbientBoost()
		{
			return 1.5f;
		}
	}
	internal sealed class CameraHook : MonoBehaviour
	{
		private struct Saved
		{
			public Color ambient;

			public float fogEnd;

			public bool fogEnabled;
		}

		private readonly Dictionary<int, Saved> _perCamSaved = new Dictionary<int, Saved>();

		public bool DisableFog = true;

		public void SyncFromConfig(EmpressFullbrightPlugin p)
		{
			DisableFog = p._disableFog.Value;
		}

		private void OnEnable()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Camera.onPreCull = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(CamPreCull));
			Camera.onPostRender = (CameraCallback)Delegate.Combine((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(CamPostRender));
		}

		private void OnDisable()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			Camera.onPreCull = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPreCull, (Delegate?)new CameraCallback(CamPreCull));
			Camera.onPostRender = (CameraCallback)Delegate.Remove((Delegate?)(object)Camera.onPostRender, (Delegate?)new CameraCallback(CamPostRender));
		}

		private void CamPreCull(Camera cam)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			if (EmpressFullbrightPlugin.Enabled && !((Object)(object)cam == (Object)null))
			{
				int instanceID = ((Object)cam).GetInstanceID();
				if (!_perCamSaved.ContainsKey(instanceID))
				{
					_perCamSaved[instanceID] = new Saved
					{
						ambient = RenderSettings.ambientLight,
						fogEnd = RenderSettings.fogEndDistance,
						fogEnabled = RenderSettings.fog
					};
				}
				float ambientBoost = EmpressFullbrightPlugin.Instance.GetAmbientBoost();
				RenderSettings.ambientMode = (AmbientMode)3;
				RenderSettings.ambientLight = new Color(ambientBoost, ambientBoost, ambientBoost, 1f);
				if (DisableFog)
				{
					RenderSettings.fogEndDistance = 500f;
				}
			}
		}

		private void CamPostRender(Camera cam)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)cam == (Object)null))
			{
				int instanceID = ((Object)cam).GetInstanceID();
				if (_perCamSaved.TryGetValue(instanceID, out var value))
				{
					RenderSettings.ambientLight = value.ambient;
					RenderSettings.fogEndDistance = value.fogEnd;
					RenderSettings.fog = value.fogEnabled;
					_perCamSaved.Remove(instanceID);
				}
			}
		}

		public void RestoreGlobals()
		{
			try
			{
				RenderSettings.ambientMode = (AmbientMode)1;
				RenderSettings.fog = true;
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(EnvironmentDirector), "Update")]
	internal static class Patch_EnvironmentDirector_Update
	{
		private static void Postfix()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			if (!EmpressFullbrightPlugin.Enabled)
			{
				return;
			}
			try
			{
				float ambientBoost = EmpressFullbrightPlugin.Instance.GetAmbientBoost();
				RenderSettings.ambientMode = (AmbientMode)3;
				RenderSettings.ambientLight = new Color(ambientBoost, ambientBoost, ambientBoost, 1f);
				EmpressFullbrightPlugin instance = EmpressFullbrightPlugin.Instance;
				if (instance != null && instance._disableFog.Value)
				{
					RenderSettings.fogEndDistance = 500f;
				}
			}
			catch
			{
			}
		}
	}
}
namespace Fullbright
{
	[BepInPlugin("Omniscye.Fullbright", "Fullbright", "1.0")]
	public class Fullbright : BaseUnityPlugin
	{
		internal static Fullbright Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}
	}
}