Decompiled source of CLGMMOGraphics v1.1.2

plugins/CLGMMOGraphics.dll

Decompiled 3 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CLGMMOGraphics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CLGMMOGraphics")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("55db1821-de2a-4937-b00b-009e0508f409")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CLGMMO;

[BepInPlugin("clgmmo.graphics.final", "CLGMMO Graphics", "1.1.2")]
public sealed class CLGMMOGraphics : BaseUnityPlugin
{
	[HarmonyPatch(typeof(FejdStartup), "Start")]
	private static class FejdStartup_Start_Patch
	{
		private static void Postfix()
		{
			try
			{
				_graphicsApplied = false;
				ProcessedLights.Clear();
				_nextApplyTime = Time.time + 2f;
				LogDebug("FejdStartup.Start detectado.");
			}
			catch
			{
			}
		}
	}

	[HarmonyPatch(typeof(Game), "Start")]
	private static class Game_Start_Patch
	{
		private static void Postfix()
		{
			try
			{
				_graphicsApplied = false;
				ProcessedLights.Clear();
				_nextApplyTime = Time.time + 2f;
				LogDebug("Game.Start detectado.");
			}
			catch
			{
			}
		}
	}

	[HarmonyPatch(typeof(Player), "OnSpawned")]
	private static class Player_OnSpawned_Patch
	{
		private static void Postfix()
		{
			try
			{
				_graphicsApplied = false;
				ProcessedLights.Clear();
				_nextApplyTime = Time.time + 1f;
				LogDebug("Player.OnSpawned detectado.");
			}
			catch
			{
			}
		}
	}

	[HarmonyPatch(typeof(EnvMan), "SetEnv")]
	private static class EnvMan_SetEnv_Patch
	{
		private static void Postfix()
		{
			try
			{
				if (ModEnabled.Value)
				{
					_graphicsApplied = false;
					_nextApplyTime = Time.time + 0.35f;
					LogDebug("EnvMan.SetEnv detectado, reagendando aplicação.");
				}
			}
			catch
			{
			}
		}
	}

	public const string ModGuid = "clgmmo.graphics.final";

	public const string ModName = "CLGMMO Graphics";

	public const string ModVersion = "1.1.2";

	internal static CLGMMOGraphics Instance;

	internal static Harmony HarmonyInstance;

	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> ModEnabled;

	internal static ConfigEntry<bool> ApplyOnStartup;

	internal static ConfigEntry<bool> ShowDebugLogs;

	internal static ConfigEntry<float> DayLightIntensityMultiplier;

	internal static ConfigEntry<float> NightLightIntensityMultiplier;

	internal static ConfigEntry<float> SunWarmth;

	internal static ConfigEntry<float> ShadowSoftness;

	internal static ConfigEntry<float> AmbientLightMultiplier;

	internal static ConfigEntry<float> FogDensityMultiplier;

	internal static ConfigEntry<float> FogStartDistance;

	internal static ConfigEntry<float> FogEndDistance;

	internal static ConfigEntry<float> SaturationMultiplier;

	internal static ConfigEntry<float> ContrastLikeMultiplier;

	internal static ConfigEntry<float> SkyColorBlend;

	internal static ConfigEntry<bool> ClampOverbrightLights;

	internal static ConfigEntry<bool> AdjustPlayerPlacedLights;

	internal static ConfigEntry<float> PlayerLightIntensityMultiplier;

	internal static ConfigEntry<float> PlayerLightRangeMultiplier;

	internal static ConfigEntry<float> AberrationReduction;

	internal static ConfigEntry<float> SoftnessReduction;

	internal static ConfigEntry<KeyboardShortcut> ReapplyHotkey;

	private static bool _graphicsApplied;

	private static float _nextApplyTime;

	internal static readonly HashSet<int> ProcessedLights = new HashSet<int>();

	private void Awake()
	{
		//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0302: Unknown result type (might be due to invalid IL or missing references)
		//IL_030c: Expected O, but got Unknown
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ModEnabled", true, "Ativa ou desativa o CLGMMOGraphics.");
		ApplyOnStartup = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ApplyOnStartup", true, "Aplica os ajustes automaticamente ao entrar no mundo.");
		ShowDebugLogs = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ShowDebugLogs", false, "Ativa logs de depuração.");
		DayLightIntensityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Lighting", "DayLightIntensityMultiplier", 1.09f, "Multiplicador da luz durante o dia.");
		NightLightIntensityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Lighting", "NightLightIntensityMultiplier", 0.92f, "Multiplicador da luz durante a noite.");
		SunWarmth = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Lighting", "SunWarmth", 1.04f, "Calor da luz do sol. 1.0 neutro, acima deixa mais quente.");
		ShadowSoftness = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Lighting", "ShadowSoftness", 0.94f, "Reduz um pouco a dureza visual das sombras pela intensidade da luz.");
		AmbientLightMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Lighting", "AmbientLightMultiplier", 1.02f, "Multiplicador da iluminação ambiente.");
		FogDensityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Atmosphere", "FogDensityMultiplier", 0.69f, "Multiplicador da densidade da neblina.");
		FogStartDistance = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Atmosphere", "FogStartDistance", 34f, "Distância inicial da neblina linear.");
		FogEndDistance = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Atmosphere", "FogEndDistance", 285f, "Distância final da neblina linear.");
		SaturationMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Color", "SaturationMultiplier", 0.93f, "Saturação geral das cores. Menor = mais natural.");
		ContrastLikeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Color", "ContrastLikeMultiplier", 1.02f, "Ajuste leve para dar mais contraste visual.");
		SkyColorBlend = ((BaseUnityPlugin)this).Config.Bind<float>("4 - Color", "SkyColorBlend", 0.06f, "Quanto o céu puxa para um tom mais natural/frio.");
		ClampOverbrightLights = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Extra Lights", "ClampOverbrightLights", true, "Limita luzes exageradas do mapa para um visual mais natural.");
		AdjustPlayerPlacedLights = ((BaseUnityPlugin)this).Config.Bind<bool>("5 - Extra Lights", "AdjustPlayerPlacedLights", true, "Ajusta tochas e luzes colocadas no mundo para combinar com o visual.");
		PlayerLightIntensityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("5 - Extra Lights", "PlayerLightIntensityMultiplier", 0.95f, "Multiplicador da intensidade das luzes de tochas/lâmpadas.");
		PlayerLightRangeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("5 - Extra Lights", "PlayerLightRangeMultiplier", 1.05f, "Multiplicador do alcance das luzes de tochas/lâmpadas.");
		AberrationReduction = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Polish", "AberrationReduction", 0.18f, "Redução leve da separação exagerada de cor nas áreas fortes. 0 a 1.");
		SoftnessReduction = ((BaseUnityPlugin)this).Config.Bind<float>("6 - Polish", "SoftnessReduction", 0.15f, "Redução leve da sensação de blur/softness excessivo. 0 a 1.");
		ReapplyHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("7 - Hotkeys", "ReapplyHotkey", new KeyboardShortcut((KeyCode)290, Array.Empty<KeyCode>()), "Tecla para reaplicar os ajustes gráficos manualmente.");
		try
		{
			HarmonyInstance = new Harmony("clgmmo.graphics.final");
			HarmonyInstance.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CLGMMO Graphics 1.1.2 carregado.");
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Falha ao inicializar CLGMMO Graphics: " + ex));
		}
	}

	private void OnDestroy()
	{
		try
		{
			if (HarmonyInstance != null)
			{
				HarmonyInstance.UnpatchSelf();
				HarmonyInstance = null;
			}
		}
		catch
		{
		}
	}

	private void Update()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		if (!ModEnabled.Value)
		{
			return;
		}
		try
		{
			KeyboardShortcut value = ReapplyHotkey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				ApplyGraphicsProfile("hotkey");
			}
			if (Time.time >= _nextApplyTime)
			{
				_nextApplyTime = Time.time + 5f;
				if (!_graphicsApplied && ApplyOnStartup.Value)
				{
					ApplyGraphicsProfile("startup");
				}
				else if (_graphicsApplied)
				{
					RefreshDynamicLights();
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Erro no Update do Graphics: " + ex));
		}
	}

	internal static void ApplyGraphicsProfile(string reason)
	{
		if ((Object)(object)Instance == (Object)null || !ModEnabled.Value)
		{
			return;
		}
		try
		{
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				LogDebug("ApplyGraphicsProfile cancelado: Camera.main ainda nula.");
				return;
			}
			GraphicsEnvironmentController.ApplyRenderSettings();
			GraphicsEnvironmentController.ApplyMainLightTuning();
			GraphicsEnvironmentController.ApplyCameraTuning(main);
			GraphicsEnvironmentController.ApplyWorldLightTuning();
			GraphicsEnvironmentController.ApplyAmbientTuning();
			GraphicsEnvironmentController.ApplyQualityPolish();
			_graphicsApplied = true;
			LogDebug("Perfil gráfico aplicado. Razão=" + reason);
		}
		catch (Exception ex)
		{
			if (Log != null)
			{
				Log.LogError((object)("Erro ao aplicar perfil gráfico: " + ex));
			}
		}
	}

	internal static void RefreshDynamicLights()
	{
		if ((Object)(object)Instance == (Object)null || !ModEnabled.Value)
		{
			return;
		}
		try
		{
			GraphicsEnvironmentController.ApplyWorldLightTuning();
			GraphicsEnvironmentController.ApplyQualityPolish();
		}
		catch
		{
		}
	}

	internal static void LogDebug(string message)
	{
		try
		{
			if (ShowDebugLogs != null && ShowDebugLogs.Value && Log != null)
			{
				Log.LogInfo((object)("[DEBUG] " + message));
			}
		}
		catch
		{
		}
	}
}
internal static class GraphicsEnvironmentController
{
	public static void ApplyRenderSettings()
	{
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_0177: Unknown result type (might be due to invalid IL or missing references)
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0198: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d4: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0200: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		//IL_0267: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			RenderSettings.fog = true;
			float fogDensity = Mathf.Clamp(RenderSettings.fogDensity * CLGMMOGraphics.FogDensityMultiplier.Value, 0.0005f, 0.017f);
			RenderSettings.fogDensity = fogDensity;
			RenderSettings.fogStartDistance = Mathf.Clamp(CLGMMOGraphics.FogStartDistance.Value, 0f, 500f);
			RenderSettings.fogEndDistance = Mathf.Clamp(CLGMMOGraphics.FogEndDistance.Value, 10f, 2000f);
			Color fogColor = RenderSettings.fogColor;
			fogColor = ColorMathUtil.AdjustSaturation(fogColor, CLGMMOGraphics.SaturationMultiplier.Value);
			fogColor = ColorMathUtil.AdjustContrastLike(fogColor, CLGMMOGraphics.ContrastLikeMultiplier.Value);
			fogColor = Color.Lerp(fogColor, new Color(0.61f, 0.68f, 0.75f, fogColor.a), 0.05f);
			fogColor = ColorMathUtil.ReduceChromaticFeeling(fogColor, CLGMMOGraphics.AberrationReduction.Value);
			RenderSettings.fogColor = fogColor;
			Color ambientSkyColor = RenderSettings.ambientSkyColor;
			ambientSkyColor = ColorMathUtil.AdjustSaturation(ambientSkyColor, CLGMMOGraphics.SaturationMultiplier.Value);
			ambientSkyColor = ColorMathUtil.AdjustContrastLike(ambientSkyColor, CLGMMOGraphics.ContrastLikeMultiplier.Value);
			ambientSkyColor = Color.Lerp(ambientSkyColor, new Color(0.56f, 0.65f, 0.75f, ambientSkyColor.a), CLGMMOGraphics.SkyColorBlend.Value);
			ambientSkyColor = ColorMathUtil.ReduceChromaticFeeling(ambientSkyColor, CLGMMOGraphics.AberrationReduction.Value);
			RenderSettings.ambientSkyColor = ambientSkyColor;
			Color ambientEquatorColor = RenderSettings.ambientEquatorColor;
			ambientEquatorColor = ColorMathUtil.AdjustSaturation(ambientEquatorColor, CLGMMOGraphics.SaturationMultiplier.Value);
			ambientEquatorColor = ColorMathUtil.AdjustContrastLike(ambientEquatorColor, CLGMMOGraphics.ContrastLikeMultiplier.Value);
			ambientEquatorColor *= CLGMMOGraphics.AmbientLightMultiplier.Value;
			ambientEquatorColor = Color.Lerp(ambientEquatorColor, new Color(0.31f, 0.34f, 0.38f, ambientEquatorColor.a), 0.07f);
			ambientEquatorColor = ColorMathUtil.ReduceChromaticFeeling(ambientEquatorColor, CLGMMOGraphics.AberrationReduction.Value);
			RenderSettings.ambientEquatorColor = ambientEquatorColor;
			Color ambientGroundColor = RenderSettings.ambientGroundColor;
			ambientGroundColor = ColorMathUtil.AdjustSaturation(ambientGroundColor, CLGMMOGraphics.SaturationMultiplier.Value * 0.98f);
			ambientGroundColor = ColorMathUtil.AdjustContrastLike(ambientGroundColor, CLGMMOGraphics.ContrastLikeMultiplier.Value);
			ambientGroundColor *= CLGMMOGraphics.AmbientLightMultiplier.Value * 0.995f;
			ambientGroundColor = Color.Lerp(ambientGroundColor, new Color(0.22f, 0.23f, 0.25f, ambientGroundColor.a), 0.1f);
			ambientGroundColor = ColorMathUtil.ReduceChromaticFeeling(ambientGroundColor, CLGMMOGraphics.AberrationReduction.Value);
			RenderSettings.ambientGroundColor = ambientGroundColor;
			if ((Object)(object)RenderSettings.sun != (Object)null)
			{
				RenderSettings.sun.color = MakeSunColorMoreNatural(RenderSettings.sun.color);
			}
			CLGMMOGraphics.LogDebug("RenderSettings ajustado.");
		}
		catch (Exception ex)
		{
			if (CLGMMOGraphics.Log != null)
			{
				CLGMMOGraphics.Log.LogError((object)("Erro em ApplyRenderSettings: " + ex));
			}
		}
	}

	public static void ApplyMainLightTuning()
	{
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Invalid comparison between Unknown and I4
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0143: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Invalid comparison between Unknown and I4
		try
		{
			Light val = RenderSettings.sun;
			if ((Object)(object)val == (Object)null)
			{
				Light[] array = Object.FindObjectsOfType<Light>();
				foreach (Light val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && (int)val2.type == 1)
					{
						val = val2;
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				CLGMMOGraphics.LogDebug("Nenhuma directional light encontrada.");
				return;
			}
			bool flag = IsNightTimeLike(val);
			float num = (flag ? CLGMMOGraphics.NightLightIntensityMultiplier.Value : CLGMMOGraphics.DayLightIntensityMultiplier.Value);
			val.intensity = Mathf.Clamp(val.intensity * num, 0.12f, 1.56f);
			val.color = MakeSunColorMoreNatural(val.color);
			if (!flag)
			{
				val.color = WarmColor(val.color, CLGMMOGraphics.SunWarmth.Value);
			}
			else
			{
				val.color = Color.Lerp(val.color, new Color(0.69f, 0.77f, 0.96f, val.color.a), 0.1f);
			}
			val.color = ColorMathUtil.ReduceChromaticFeeling(val.color, CLGMMOGraphics.AberrationReduction.Value);
			if ((int)QualitySettings.shadows > 0)
			{
				val.shadowStrength = Mathf.Clamp(val.shadowStrength * CLGMMOGraphics.ShadowSoftness.Value, 0.28f, 0.88f);
			}
			CLGMMOGraphics.LogDebug("Directional light ajustada. Night=" + flag);
		}
		catch (Exception ex)
		{
			if (CLGMMOGraphics.Log != null)
			{
				CLGMMOGraphics.Log.LogError((object)("Erro em ApplyMainLightTuning: " + ex));
			}
		}
	}

	public static void ApplyCameraTuning(Camera cam)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: 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)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)cam == (Object)null)
		{
			return;
		}
		try
		{
			cam.allowHDR = true;
			cam.allowMSAA = true;
			cam.nearClipPlane = Mathf.Clamp(cam.nearClipPlane, 0.01f, 0.2f);
			cam.farClipPlane = Mathf.Clamp(cam.farClipPlane, 700f, 5000f);
			Color backgroundColor = cam.backgroundColor;
			backgroundColor = ColorMathUtil.AdjustSaturation(backgroundColor, CLGMMOGraphics.SaturationMultiplier.Value);
			backgroundColor = ColorMathUtil.AdjustContrastLike(backgroundColor, CLGMMOGraphics.ContrastLikeMultiplier.Value);
			backgroundColor = ColorMathUtil.ReduceChromaticFeeling(backgroundColor, CLGMMOGraphics.AberrationReduction.Value);
			cam.backgroundColor = backgroundColor;
			CLGMMOGraphics.LogDebug("Camera ajustada.");
		}
		catch (Exception ex)
		{
			if (CLGMMOGraphics.Log != null)
			{
				CLGMMOGraphics.Log.LogError((object)("Erro em ApplyCameraTuning: " + ex));
			}
		}
	}

	public static void ApplyAmbientTuning()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Material skybox = RenderSettings.skybox;
			if (!((Object)(object)skybox == (Object)null))
			{
				if (skybox.HasProperty("_Tint"))
				{
					Color color = skybox.GetColor("_Tint");
					color = ColorMathUtil.AdjustSaturation(color, CLGMMOGraphics.SaturationMultiplier.Value);
					color = ColorMathUtil.AdjustContrastLike(color, CLGMMOGraphics.ContrastLikeMultiplier.Value);
					color = Color.Lerp(color, new Color(0.89f, 0.94f, 0.99f, color.a), CLGMMOGraphics.SkyColorBlend.Value * 0.32f);
					color = ColorMathUtil.ReduceChromaticFeeling(color, CLGMMOGraphics.AberrationReduction.Value);
					skybox.SetColor("_Tint", color);
				}
				if (skybox.HasProperty("_Exposure"))
				{
					float @float = skybox.GetFloat("_Exposure");
					float num = Mathf.Clamp01(CLGMMOGraphics.SoftnessReduction.Value);
					@float = Mathf.Clamp(@float * Mathf.Lerp(0.96f, 0.93f, num), 0.62f, 1.22f);
					skybox.SetFloat("_Exposure", @float);
				}
				DynamicGI.UpdateEnvironment();
				CLGMMOGraphics.LogDebug("Ambiente e skybox ajustados.");
			}
		}
		catch (Exception ex)
		{
			if (CLGMMOGraphics.Log != null)
			{
				CLGMMOGraphics.Log.LogError((object)("Erro em ApplyAmbientTuning: " + ex));
			}
		}
	}

	public static void ApplyWorldLightTuning()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Invalid comparison between Unknown and I4
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0183: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: 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_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_0191: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			Light[] array = Object.FindObjectsOfType<Light>();
			if (array == null || array.Length == 0)
			{
				return;
			}
			foreach (Light val in array)
			{
				if ((Object)(object)val == (Object)null || (int)val.type == 1)
				{
					continue;
				}
				int instanceID = ((Object)val).GetInstanceID();
				if (_CanProcessLight(val) && (CLGMMOGraphics.AdjustPlayerPlacedLights.Value || !_LooksLikePlacedLight(val)))
				{
					if (CLGMMOGraphics.ClampOverbrightLights.Value)
					{
						val.intensity = Mathf.Clamp(val.intensity, 0.1f, 1.8f);
					}
					if (_LooksLikePlacedLight(val))
					{
						val.intensity = Mathf.Clamp(val.intensity * CLGMMOGraphics.PlayerLightIntensityMultiplier.Value, 0.12f, 1.78f);
						val.range = Mathf.Clamp(val.range * CLGMMOGraphics.PlayerLightRangeMultiplier.Value, 1.5f, 29f);
						val.color = Color.Lerp(val.color, new Color(0.98f, 0.84f, 0.67f, val.color.a), 0.1f);
					}
					else
					{
						val.intensity = Mathf.Clamp(val.intensity * 0.95f, 0.05f, 1.75f);
						val.color = ColorMathUtil.AdjustSaturation(val.color, 0.94f);
					}
					val.color = ColorMathUtil.ReduceChromaticFeeling(val.color, CLGMMOGraphics.AberrationReduction.Value);
					if (!CLGMMOGraphics.ProcessedLights.Contains(instanceID))
					{
						CLGMMOGraphics.ProcessedLights.Add(instanceID);
						CLGMMOGraphics.LogDebug("Light ajustada: " + ((Object)val).name + " id=" + instanceID);
					}
				}
			}
		}
		catch (Exception ex)
		{
			if (CLGMMOGraphics.Log != null)
			{
				CLGMMOGraphics.Log.LogError((object)("Erro em ApplyWorldLightTuning: " + ex));
			}
		}
	}

	public static void ApplyQualityPolish()
	{
		try
		{
			float num = Mathf.Clamp01(CLGMMOGraphics.SoftnessReduction.Value);
			QualitySettings.masterTextureLimit = 0;
			QualitySettings.anisotropicFiltering = (AnisotropicFiltering)2;
			QualitySettings.lodBias = Mathf.Clamp(1.35f + num * 0.2f, 1.1f, 1.7f);
			QualitySettings.antiAliasing = 4;
		}
		catch
		{
		}
	}

	private static bool _CanProcessLight(Light light)
	{
		if ((Object)(object)light == (Object)null)
		{
			return false;
		}
		if (!((Component)light).gameObject.activeInHierarchy)
		{
			return false;
		}
		return true;
	}

	private static bool _LooksLikePlacedLight(Light light)
	{
		if ((Object)(object)light == (Object)null)
		{
			return false;
		}
		string name = ((Object)light).name;
		if (string.IsNullOrEmpty(name))
		{
			return false;
		}
		return ContainsAny(name, "torch", "fire", "sconce", "brazier", "lamp", "lantern", "standing", "groundtorch", "walltorch", "piece");
	}

	private static bool ContainsAny(string text, params string[] terms)
	{
		if (string.IsNullOrEmpty(text) || terms == null)
		{
			return false;
		}
		foreach (string value in terms)
		{
			if (!string.IsNullOrEmpty(value) && text.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return true;
			}
		}
		return false;
	}

	private static bool IsNightTimeLike(Light sun)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)sun == (Object)null)
		{
			return false;
		}
		if (sun.intensity < 0.35f)
		{
			return true;
		}
		Quaternion rotation = ((Component)sun).transform.rotation;
		Vector3 eulerAngles = ((Quaternion)(ref rotation)).eulerAngles;
		float num = eulerAngles.x;
		if (num > 180f)
		{
			num -= 360f;
		}
		return num < -5f || num > 170f;
	}

	private static Color MakeSunColorMoreNatural(Color input)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//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_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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_0038: Unknown result type (might be due to invalid IL or missing references)
		Color color = ColorMathUtil.AdjustSaturation(input, CLGMMOGraphics.SaturationMultiplier.Value);
		color = ColorMathUtil.AdjustContrastLike(color, CLGMMOGraphics.ContrastLikeMultiplier.Value);
		return ColorMathUtil.ReduceChromaticFeeling(color, CLGMMOGraphics.AberrationReduction.Value);
	}

	private static Color WarmColor(Color input, float warmth)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: 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_005f: 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)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Clamp(warmth, 0.7f, 1.5f);
		Color val = default(Color);
		((Color)(ref val))..ctor(Mathf.Clamp01(input.r * num), Mathf.Clamp01(input.g * (0.98f + (num - 1f) * 0.35f)), Mathf.Clamp01(input.b * (1.02f - (num - 1f) * 0.45f)), input.a);
		return Color.Lerp(input, val, 0.38f);
	}
}
internal static class ColorMathUtil
{
	public static Color AdjustSaturation(Color color, float saturation)
	{
		//IL_0012: 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)
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Clamp(saturation, 0f, 2f);
		float num2 = (color.r + color.g + color.b) / 3f;
		return new Color(Mathf.Clamp01(num2 + (color.r - num2) * num), Mathf.Clamp01(num2 + (color.g - num2) * num), Mathf.Clamp01(num2 + (color.b - num2) * num), color.a);
	}

	public static Color AdjustContrastLike(Color color, float contrast)
	{
		//IL_0012: 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_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Clamp(contrast, 0.5f, 1.5f);
		return new Color(Mathf.Clamp01((color.r - 0.5f) * num + 0.5f), Mathf.Clamp01((color.g - 0.5f) * num + 0.5f), Mathf.Clamp01((color.b - 0.5f) * num + 0.5f), color.a);
	}

	public static Color ReduceChromaticFeeling(Color color, float amount)
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: 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_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Clamp01(amount);
		if (num <= 0f)
		{
			return color;
		}
		float num2 = (color.r + color.g + color.b) / 3f;
		return new Color(Mathf.Clamp01(Mathf.Lerp(color.r, num2, num * 0.22f)), Mathf.Clamp01(Mathf.Lerp(color.g, num2, num * 0.16f)), Mathf.Clamp01(Mathf.Lerp(color.b, num2, num * 0.26f)), color.a);
	}
}