Decompiled source of LightingTweaks v1.0.4

LightingTweaks.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Linq;
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 Peak;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using Zorro.Core;

[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: AssemblyCompany("LightingTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d329334d435c3517233d9efd0d0ce07ec3e4b16f")]
[assembly: AssemblyProduct("LightingTweaks")]
[assembly: AssemblyTitle("LightingTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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;
		}
	}
}
internal class BiomeMoonConfig
{
	public string Key { get; set; }

	public BiomeType Biome { get; set; }

	public Color? MoonColorStart { get; set; }

	public Color? MoonColorMid { get; set; }

	public Color? MoonColorEnd { get; set; }

	public float? MoonIntensity { get; set; }

	public float? AmbientDarkness { get; set; }

	public float? BrightnessTarget { get; set; }

	public float? AmbienceStrengthTarget { get; set; }

	public float? AmbienceMin { get; set; }

	public float? DuskStart { get; set; }

	public float? NightStart { get; set; }

	public float? PeakStart { get; set; }

	public float? PeakEnd { get; set; }

	public float? NightEnd { get; set; }

	public float? DawnStart { get; set; }

	public bool HasCustomStart => MoonColorStart.HasValue;

	public bool HasCustomMid => MoonColorMid.HasValue;

	public bool HasCustomEnd => MoonColorEnd.HasValue;

	public bool HasCustomIntensity => MoonIntensity.HasValue;

	public bool HasCustomAmbient => AmbientDarkness.HasValue;
}
namespace TechnicalTweaks
{
	[BepInPlugin("jill920.LightingTweaks", "Lighting Tweaks", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> ItemLight;

		internal static ConfigEntry<bool> KilnTweak;

		internal static ConfigEntry<bool> CitadelTweak;

		internal static ConfigEntry<bool> MoonLightEnable;

		internal static float MoonIntensityMin = 0.015f;

		internal static float MoonIntensityMax = 4f;

		internal static ConfigEntry<bool> AmbientEnable;

		internal static BiomeMoonConfig[] BiomeConfigs = new BiomeMoonConfig[11]
		{
			new BiomeMoonConfig
			{
				Key = "SHORE",
				Biome = (BiomeType)0,
				MoonColorMid = new Color(0.6f, 0.7f, 1f, 0.7f),
				MoonIntensity = 1f,
				AmbienceStrengthTarget = 0.8f,
				AmbienceMin = 0.1f
			},
			new BiomeMoonConfig
			{
				Key = "TROPICS",
				Biome = (BiomeType)1,
				MoonColorMid = new Color(0.7f, 0.9f, 1f, 1f),
				MoonIntensity = 1f,
				AmbienceStrengthTarget = 0.65f,
				AmbienceMin = 0.065f
			},
			new BiomeMoonConfig
			{
				Key = "ALPINE",
				Biome = (BiomeType)2,
				MoonColorMid = new Color(0.5f, 0.8f, 1f, 1f),
				MoonIntensity = 4f,
				AmbienceStrengthTarget = 0.7f,
				AmbienceMin = 0.13f
			},
			new BiomeMoonConfig
			{
				Key = "MESA",
				Biome = (BiomeType)6,
				MoonColorMid = new Color(0.8f, 0.8f, 0.55f, 1f),
				MoonIntensity = 3f,
				AmbienceStrengthTarget = 0.25f,
				AmbienceMin = 0.025f
			},
			new BiomeMoonConfig
			{
				Key = "ROOTS",
				Biome = (BiomeType)7,
				MoonColorStart = new Color(0.15f, 0.09f, 0.2f, 0.15f),
				MoonColorMid = new Color(0.3f, 0.7f, 1f, 1f),
				MoonColorEnd = new Color(1f, 0.5f, 0.8f, 1f),
				MoonIntensity = 4f,
				AmbienceStrengthTarget = 0.75f,
				AmbienceMin = 0.05f
			},
			new BiomeMoonConfig
			{
				Key = "GLOOM",
				Biome = (BiomeType)8,
				MoonColorStart = new Color(0.15f, 0.09f, 0.2f, 0.15f),
				MoonColorMid = new Color(0.7f, 0.6f, 0.9f, 1f),
				MoonColorEnd = new Color(0.15f, 0.09f, 0.2f, 0.15f),
				MoonIntensity = 2f,
				AmbienceStrengthTarget = 0.8f,
				AmbienceMin = 0.02f
			},
			new BiomeMoonConfig
			{
				Key = "THE CITADEL",
				Biome = (BiomeType)9,
				MoonColorStart = new Color(0.3f, 0.5f, 0.7f, 0f),
				MoonColorMid = new Color(0.5f, 0.8f, 1f, 0f),
				MoonColorEnd = new Color(0.3f, 0.5f, 0.7f, 0f),
				MoonIntensity = 0f,
				AmbienceStrengthTarget = 0.8f,
				AmbienceMin = 0.01f
			},
			new BiomeMoonConfig
			{
				Key = "NADIR",
				Biome = (BiomeType)17,
				MoonColorStart = new Color(0.05f, 0.02f, 0.1f, 1f),
				MoonColorMid = new Color(0.1f, 0.05f, 0.3f, 1f),
				MoonColorEnd = new Color(0.05f, 0.02f, 0.1f, 1f),
				MoonIntensity = 5f,
				AmbienceStrengthTarget = 0.8f,
				AmbienceMin = 0.1f
			},
			new BiomeMoonConfig
			{
				Key = "PEAK",
				Biome = (BiomeType)5,
				MoonColorMid = new Color(0.4f, 0.5f, 1f, 0f),
				MoonIntensity = 0f,
				AmbienceStrengthTarget = 0.8f,
				AmbienceMin = 0.1f
			},
			new BiomeMoonConfig
			{
				Key = "CALDERA",
				Biome = (BiomeType)3,
				MoonColorMid = new Color(1f, 0.55f, 0.25f, 1f),
				MoonIntensity = 3f,
				AmbienceStrengthTarget = 0.7f,
				AmbienceMin = 0.13f
			},
			new BiomeMoonConfig
			{
				Key = "THE KILN",
				Biome = (BiomeType)3,
				MoonColorMid = new Color(1f, 0.35f, 0.15f, 0.5f),
				MoonIntensity = 0.4f,
				AmbienceStrengthTarget = 0.1f,
				AmbienceMin = 0.02f
			}
		};

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			_harmony = new Harmony("jill920.technicaltweaks");
			ItemLight = ((BaseUnityPlugin)this).Config.Bind<bool>("Item Lights", "Enable", true, "Enable item light emission. Default: true");
			KilnTweak = ((BaseUnityPlugin)this).Config.Bind<bool>("Biome Tweak", "Kiln", true, "Enable tweaks for Kiln (Needs reload). Default: true");
			CitadelTweak = ((BaseUnityPlugin)this).Config.Bind<bool>("Biome Tweak", "Citadel", true, "Enable tweaks for Citadel (Needs reload). Default: true");
			MoonLightEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Moon Shadows", "Enable", true, "Enable Moon light at night. Default: true");
			AmbientEnable = ((BaseUnityPlugin)this).Config.Bind<bool>("Ambient Darkness", "Enable", true, "Enable per-biome custom darkness. Default: true");
			Log = ((BaseUnityPlugin)this).Logger;
			_harmony.PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Technical Tweaks loaded successfully!");
		}
	}
}
namespace TechnicalTweaks.Patches
{
	internal static class AmbientDarknessCore
	{
		internal static readonly int _brightnessID = Shader.PropertyToID("_Brightness");

		internal static readonly int _ambienceStrengthID = Shader.PropertyToID("_AmbienceStrength");

		internal static readonly int _ambienceMinID = Shader.PropertyToID("_AmbienceMin");

		internal static readonly int _brightnessAltID = Shader.PropertyToID("brightness");

		internal static readonly int _ambienceStrengthAltID = Shader.PropertyToID("ambienceStrength");

		internal static readonly int _ambienceMinAltID = Shader.PropertyToID("ambienceMin");

		internal const float AMBIENCE_MIN_FLOOR = 0f;

		internal const float AMBIENCE_MIN_VANILLA = 0.2f;

		internal const float BRIGHTNESS_MAX = 1f;

		public static void Apply()
		{
			if (!((Object)(object)DayNightManager.instance == (Object)null))
			{
				if (!IsInGameScene() || !Plugin.AmbientEnable.Value)
				{
					SetShaderValues(1f, 1f, 0.2f);
					return;
				}
				float timeOfDayNormalized = DayNightManager.instance.timeOfDayNormalized;
				float moonVisibility = BiomeMoonManager.GetMoonVisibility(timeOfDayNormalized);
				BiomeMoonConfig currentConfig = BiomeMoonManager.GetCurrentConfig();
				float num = Mathf.Clamp(currentConfig?.BrightnessTarget ?? 1f, 0f, 1f);
				float num2 = Mathf.Max(currentConfig?.AmbienceStrengthTarget ?? 1f, 0f);
				float num3 = Mathf.Max((currentConfig?.AmbienceMin).GetValueOrDefault(), 0f);
				float brightness = Mathf.Lerp(1f, num, moonVisibility);
				float ambienceStrength = Mathf.Lerp(1f, num2, moonVisibility);
				float ambienceMin = Mathf.Lerp(0.2f, num3, moonVisibility);
				SetShaderValues(brightness, ambienceStrength, ambienceMin);
			}
		}

		private static bool IsInGameScene()
		{
			MountainProgressHandler instance = Singleton<MountainProgressHandler>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			if (instance.progressPoints == null || instance.progressPoints.Length == 0)
			{
				return false;
			}
			if ((Object)(object)Character.localCharacter == (Object)null)
			{
				return false;
			}
			return true;
		}

		private static void SetShaderValues(float brightness, float ambienceStrength, float ambienceMin)
		{
			Shader.SetGlobalFloat("_Brightness", brightness);
			Shader.SetGlobalFloat("_AmbienceStrength", ambienceStrength);
			Shader.SetGlobalFloat("_AmbienceMin", ambienceMin);
			Shader.SetGlobalFloat("brightness", brightness);
			Shader.SetGlobalFloat("ambienceStrength", ambienceStrength);
			Shader.SetGlobalFloat("ambienceMin", ambienceMin);
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "UpdateCycle")]
	internal static class DayNightManager_UpdateCycle_AmbientPatch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			AmbientDarknessCore.Apply();
		}
	}
	[HarmonyPatch(typeof(MountainProgressHandler), "SetSegmentComplete")]
	internal static class MountainProgressHandler_SetSegmentComplete_Patch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			BiomeMoonManager.UpdateCurrentBiome();
			AmbientDarknessCore.Apply();
		}
	}
	[HarmonyPatch(typeof(MountainProgressHandler), "JumpToSegment")]
	internal static class MountainProgressHandler_JumpToSegment_Patch
	{
		[HarmonyPostfix]
		private static void Postfix()
		{
			BiomeMoonManager.UpdateCurrentBiome();
			AmbientDarknessCore.Apply();
		}
	}
	[HarmonyPatch]
	internal static class LightVolume_AmbientPatch
	{
		private static MethodInfo _targetMethod;

		private static MethodInfo TargetMethod()
		{
			if (_targetMethod != null)
			{
				return _targetMethod;
			}
			try
			{
				Type type = Type.GetType("LightVolume, LightVolume.Runtime");
				if (type != null)
				{
					_targetMethod = type.GetMethod("SetShaderVars", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
			}
			catch
			{
			}
			return _targetMethod;
		}

		[HarmonyPostfix]
		private static void Postfix()
		{
			AmbientDarknessCore.Apply();
		}
	}
	public class AdvancedLightFlicker : MonoBehaviour
	{
		private Light _light;

		private AudioSource _audioSource;

		private Vector3 _basePosition;

		private float _baseIntensity;

		private float _timer;

		public void Init(float baseIntensity, Vector3 baseLocalPosition)
		{
			//IL_0021: 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)
			_light = ((Component)this).GetComponent<Light>();
			_audioSource = ((Component)this).GetComponent<AudioSource>();
			_baseIntensity = baseIntensity;
			_basePosition = baseLocalPosition;
			_timer = Random.Range(0f, 100f);
		}

		private void Update()
		{
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_light))
			{
				return;
			}
			if ((Object)(object)_audioSource != (Object)null && !((Behaviour)_audioSource).enabled)
			{
				if (((Behaviour)_light).enabled)
				{
					((Behaviour)_light).enabled = false;
				}
			}
			else if (((Behaviour)_light).enabled)
			{
				_timer += Time.deltaTime * 1.2f;
				float timer = _timer;
				float num = Mathf.Sin(timer * 4.2f) * 0.2f;
				float num2 = Mathf.Sin(timer * 6.8f + 1.5f) * 0.15f;
				float num3 = Mathf.Sin(timer * 9.3f + 3.7f) * 0.08f;
				float num4 = Mathf.Sign(Mathf.Sin(timer * 2.3f)) * 0.1f;
				float num5 = (0f - Mathf.Sign(Mathf.Sin(timer * 3.1f + 0.8f))) * 0.08f;
				float num6 = num + num2 + num3 + num4 + num5;
				float num7 = 1f + num6;
				num7 = Mathf.Clamp(num7, 0.9f, 1.1f);
				_light.intensity = _baseIntensity * num7;
				float num8 = Mathf.Sin(timer * 2.8f) * 0.25f;
				float num9 = Mathf.Sin(timer * 4.5f + 2.1f) * 0.18f;
				float num10 = Mathf.Sin(timer * 5.9f + 1.3f) * 0.12f;
				float num11 = Mathf.Sign(Mathf.Sin(timer * 1.7f + 0.4f)) * 0.08f;
				float num12 = Mathf.Sign(Mathf.Sin(timer * 2.2f + 1.1f)) * 0.06f;
				float num13 = Mathf.Sign(Mathf.Sin(timer * 1.9f + 2.5f)) * 0.08f;
				Vector3 val = default(Vector3);
				((Vector3)(ref val))..ctor(num8 + num11, num9 + num12, num10 + num13);
				((Component)this).transform.localPosition = _basePosition + val;
			}
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class GhostFire_Pyre_LightPatch
	{
		private const string TargetName = "BlueFlame";

		private const string ParentPathSubString = "Ghost Fires/Belltower/Pyre";

		[HarmonyPostfix]
		private static void Postfix()
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == "BlueFlame" && GetHierarchyPath(val).Contains("Ghost Fires/Belltower/Pyre"))
				{
					SetupFakeLight(((Component)val).gameObject);
				}
			}
		}

		private static void SetupFakeLight(GameObject go)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_005c: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)go.transform.Find("PyreLightSource") != (Object)null))
			{
				GameObject val = new GameObject("PyreLightSource");
				val.transform.SetParent(go.transform, false);
				Vector3 val2 = default(Vector3);
				((Vector3)(ref val2))..ctor(0f, 0f, 2f);
				val.transform.localPosition = val2;
				Light val3 = val.AddComponent<Light>();
				val.AddComponent<UniversalAdditionalLightData>();
				val3.type = (LightType)2;
				val3.intensity = 10f;
				val3.range = 18f;
				val3.color = new Color(0.65f, 0f, 1f, 1f);
				val3.shadows = (LightShadows)2;
				((Behaviour)val3).enabled = true;
				AdvancedLightFlicker advancedLightFlicker = val.AddComponent<AdvancedLightFlicker>();
				advancedLightFlicker.Init(10f, val2);
			}
		}

		private static string GetHierarchyPath(Transform transform)
		{
			string text = ((Object)transform).name;
			while ((Object)(object)transform.parent != (Object)null)
			{
				transform = transform.parent;
				text = ((Object)transform).name + "/" + text;
			}
			return text;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class SleepyFog_Plane_ShadowPatch
	{
		private const string TargetParentName = "SleepyFog";

		private const string TargetChildName = "Plane";

		[HarmonyPostfix]
		private static void Postfix()
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Invalid comparison between Unknown and I4
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			int num = 0;
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name != "SleepyFog")
				{
					continue;
				}
				Transform val2 = val.Find("Plane");
				if (!((Object)(object)val2 == (Object)null))
				{
					MeshRenderer component = ((Component)val2).GetComponent<MeshRenderer>();
					if (!((Object)(object)component == (Object)null) && (int)((Renderer)component).shadowCastingMode > 0)
					{
						((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
						num++;
					}
				}
			}
			if (num > 0)
			{
				Plugin.Log.LogInfo((object)$"[SleepyFog] Disabled castShadows on {num} Plane renderer(s)");
			}
		}
	}
	internal static class BiomeMoonManager
	{
		private struct Phases
		{
			public float DuskStart;

			public float NightStart;

			public float PeakStart;

			public float PeakEnd;

			public float NightEnd;

			public float DawnStart;
		}

		private static string _currentBiomeKey = "SHORE";

		private static BiomeType _currentBiome = (BiomeType)0;

		private static BiomeMoonConfig _currentConfig;

		private static int _currentSegment = -1;

		private static bool _isInitialized;

		public static BiomeType GetCurrentBiome()
		{
			//IL_0013: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!_isInitialized)
			{
				UpdateCurrentBiome();
			}
			return _currentBiome;
		}

		public static string GetCurrentBiomeKey()
		{
			if (!_isInitialized)
			{
				UpdateCurrentBiome();
			}
			return _currentBiomeKey;
		}

		public static BiomeMoonConfig GetCurrentConfig()
		{
			if (_currentConfig == null || !_isInitialized)
			{
				UpdateCurrentBiome();
			}
			return _currentConfig;
		}

		public static void UpdateCurrentBiome()
		{
			//IL_005e: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				MountainProgressHandler instance = Singleton<MountainProgressHandler>.Instance;
				if ((Object)(object)instance == (Object)null || instance.progressPoints == null)
				{
					SetCurrentBiome("SHORE", (BiomeType)0);
					return;
				}
				int maxProgressPointReached = instance.maxProgressPointReached;
				if (maxProgressPointReached == _currentSegment && _isInitialized)
				{
					return;
				}
				_currentSegment = maxProgressPointReached;
				BiomeType biome = (BiomeType)0;
				string key = "SHORE";
				if (maxProgressPointReached >= 0 && maxProgressPointReached < instance.progressPoints.Length)
				{
					ProgressPoint val = instance.progressPoints[maxProgressPointReached];
					biome = val.biome;
					if (!string.IsNullOrEmpty(val.title))
					{
						key = val.title;
					}
				}
				else if (maxProgressPointReached >= instance.progressPoints.Length)
				{
					biome = (BiomeType)5;
					key = "PEAK";
				}
				SetCurrentBiome(key, biome);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[BiomeMoon] Failed to update biome: " + ex.Message));
				SetCurrentBiome("SHORE", (BiomeType)0);
			}
		}

		private static void SetCurrentBiome(string key, BiomeType biome)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			if (!(key == _currentBiomeKey) || biome != _currentBiome || !_isInitialized)
			{
				_currentBiomeKey = key;
				_currentBiome = biome;
				_currentConfig = GetConfigForKey(key, biome);
				_isInitialized = true;
			}
		}

		private static BiomeMoonConfig GetConfigForKey(string key, BiomeType biome)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			BiomeMoonConfig biomeMoonConfig = Plugin.BiomeConfigs.FirstOrDefault((BiomeMoonConfig c) => c.Key == key);
			if (biomeMoonConfig != null)
			{
				return biomeMoonConfig;
			}
			return Plugin.BiomeConfigs.FirstOrDefault((BiomeMoonConfig c) => c.Biome == biome);
		}

		private static Phases GetPhases(BiomeMoonConfig cfg)
		{
			return new Phases
			{
				DuskStart = (cfg?.DuskStart ?? 0.708f),
				NightStart = (cfg?.NightStart ?? 0.875f),
				PeakStart = (cfg?.PeakStart ?? 0.916f),
				PeakEnd = (cfg?.PeakEnd ?? 0.083f),
				NightEnd = (cfg?.NightEnd ?? 0.166f),
				DawnStart = (cfg?.DawnStart ?? 0.208f)
			};
		}

		public static float GetMoonVisibility(float timeOfDayNormalized)
		{
			Phases phases = GetPhases(_currentConfig);
			if (timeOfDayNormalized >= phases.DuskStart && timeOfDayNormalized < phases.PeakStart)
			{
				return TechnicalTweaksHelper.SmoothStep(phases.DuskStart, phases.PeakStart, timeOfDayNormalized);
			}
			if (timeOfDayNormalized >= phases.PeakStart || timeOfDayNormalized < phases.PeakEnd)
			{
				return 1f;
			}
			if (timeOfDayNormalized >= phases.PeakEnd && timeOfDayNormalized < phases.DawnStart)
			{
				return 1f - TechnicalTweaksHelper.SmoothStep(phases.PeakEnd, phases.DawnStart, timeOfDayNormalized);
			}
			return 0f;
		}

		public static Color GetMoonColor(float timeOfDayNormalized, Color sunColor)
		{
			//IL_003c: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			Phases phases = GetPhases(_currentConfig);
			Color val = (Color)(((??)_currentConfig?.MoonColorStart) ?? TechnicalTweaksHelper.DEFAULT_MOON_START);
			Color val2 = (Color)(((??)_currentConfig?.MoonColorMid) ?? TechnicalTweaksHelper.DEFAULT_MOON_MID);
			Color val3 = (Color)(((??)_currentConfig?.MoonColorEnd) ?? TechnicalTweaksHelper.DEFAULT_MOON_END);
			if (timeOfDayNormalized >= phases.DuskStart && timeOfDayNormalized < phases.NightStart)
			{
				float num = TechnicalTweaksHelper.SmoothStep(phases.DuskStart, phases.NightStart, timeOfDayNormalized);
				return Color.Lerp(sunColor, val, num);
			}
			if (timeOfDayNormalized >= phases.NightStart && timeOfDayNormalized < phases.PeakStart)
			{
				float num2 = TechnicalTweaksHelper.SmoothStep(phases.NightStart, phases.PeakStart, timeOfDayNormalized);
				return Color.Lerp(val, val2, num2);
			}
			if (timeOfDayNormalized >= phases.PeakStart || timeOfDayNormalized < phases.PeakEnd)
			{
				return val2;
			}
			if (timeOfDayNormalized >= phases.PeakEnd && timeOfDayNormalized < phases.NightEnd)
			{
				float num3 = TechnicalTweaksHelper.SmoothStep(phases.PeakEnd, phases.NightEnd, timeOfDayNormalized);
				return Color.Lerp(val2, val3, num3);
			}
			if (timeOfDayNormalized >= phases.NightEnd && timeOfDayNormalized < phases.DawnStart)
			{
				float num4 = TechnicalTweaksHelper.SmoothStep(phases.NightEnd, phases.DawnStart, timeOfDayNormalized);
				return Color.Lerp(val3, sunColor, num4);
			}
			return sunColor;
		}

		public static float GetMoonIntensity(float timeOfDayNormalized)
		{
			float num = _currentConfig?.MoonIntensity ?? Plugin.MoonIntensityMax;
			float moonIntensityMin = Plugin.MoonIntensityMin;
			float moonVisibility = GetMoonVisibility(timeOfDayNormalized);
			return Mathf.Lerp(moonIntensityMin, num, moonVisibility);
		}

		public static float GetAmbientDarkness()
		{
			if (_currentConfig != null && _currentConfig.HasCustomAmbient)
			{
				return _currentConfig.AmbientDarkness.Value;
			}
			return 1f;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class CloudRingOnVolcanoModel
	{
		private const string PEAK_KILN_PARENT_PATH = "Map/Biome_4/Caldera/Volcano/Volcano_Segment/Peak_Kiln Variant";

		private const string SOURCE_RING_NAME = "Cloud Ring (1)";

		private const string NEW_RING_NAME = "Cloud Ring (3)";

		private const string VOLCANO_MODEL_PATH = "Map/Biome_4/Caldera/VolcanoModel";

		[HarmonyPostfix]
		private static void Postfix()
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = FindCloudRing();
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[CloudRing3] Source 'Cloud Ring (1)' not found");
				return;
			}
			GameObject val2 = GameObject.Find("Map/Biome_4/Caldera/VolcanoModel");
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = FindByName("VolcanoModel");
			}
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[CloudRing3] 'VolcanoModel' destination not found");
				return;
			}
			if ((Object)(object)val2.transform.Find("Cloud Ring (3)") != (Object)null)
			{
				Plugin.Log.LogInfo((object)"[CloudRing3] 'Cloud Ring (3)' already present — skipping");
				return;
			}
			GameObject val3 = Object.Instantiate<GameObject>(val);
			((Object)val3).name = "Cloud Ring (3)";
			val3.transform.SetParent(val2.transform, false);
			val3.transform.localPosition = new Vector3(0f, 7f, -1f);
			val3.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			val3.transform.localScale = new Vector3(2.2f, 2.2f, 2.2f);
			ParticleSystem component = val3.GetComponent<ParticleSystem>();
			ParticleSystemRenderer component2 = val3.GetComponent<ParticleSystemRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				MainModule main = component.main;
				ShapeModule shape = component.shape;
				((MainModule)(ref main)).startSize = MinMaxCurve.op_Implicit(45f);
				((MainModule)(ref main)).maxParticles = 100;
				((ShapeModule)(ref shape)).donutRadius = 12f;
				((MainModule)(ref main)).startLifetime = new MinMaxCurve(8f, 12f);
				((MainModule)(ref main)).prewarm = true;
				((MainModule)(ref main)).loop = true;
				if ((Object)(object)component2 != (Object)null)
				{
					Material val4 = FindMaterial("VolumeParticles");
					if ((Object)(object)val4 != (Object)null)
					{
						((Renderer)component2).sharedMaterial = val4;
						Plugin.Log.LogInfo((object)("[CloudRing3] Renderer material → " + ((Object)val4).name));
					}
					else
					{
						Plugin.Log.LogWarning((object)"[CloudRing3] 'VolumeParticlesThick' not found — keeping original");
					}
					if (component2.maxParticleSize < 1f)
					{
						component2.maxParticleSize = 1f;
					}
				}
			}
			val3.SetActive(true);
			if ((Object)(object)component != (Object)null)
			{
				component.Clear(true);
				if (!component.isPlaying)
				{
					component.Play();
				}
				MainModule main2 = component.main;
				ManualLogSource log = Plugin.Log;
				string[] obj = new string[7]
				{
					"[CloudRing3] Spawned 'Cloud Ring (3)' | ",
					$"localPos={val3.transform.localPosition} ",
					$"worldPos={val3.transform.position} ",
					null,
					null,
					null,
					null
				};
				MinMaxCurve val5 = ((MainModule)(ref main2)).startSize;
				obj[3] = $"startSize={((MinMaxCurve)(ref val5)).constant} ";
				ShapeModule shape2 = component.shape;
				obj[4] = $"donutRadius={((ShapeModule)(ref shape2)).donutRadius} ";
				val5 = ((MainModule)(ref main2)).startLifetime;
				object arg = ((MinMaxCurve)(ref val5)).constantMin;
				val5 = ((MainModule)(ref main2)).startLifetime;
				obj[5] = $"lifetime={arg}..{((MinMaxCurve)(ref val5)).constantMax} ";
				obj[6] = $"prewarm={((MainModule)(ref main2)).prewarm}";
				log.LogInfo((object)string.Concat(obj));
			}
		}

		private static GameObject FindCloudRing()
		{
			GameObject val = GameObject.Find("Map/Biome_4/Caldera/Volcano/Volcano_Segment/Peak_Kiln Variant");
			if ((Object)(object)val != (Object)null)
			{
				Transform val2 = val.transform.Find("Cloud Ring (1)");
				if ((Object)(object)val2 != (Object)null)
				{
					return ((Component)val2).gameObject;
				}
			}
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val3 in array2)
			{
				if (((Object)val3).name == "Cloud Ring (1)")
				{
					return ((Component)val3).gameObject;
				}
			}
			return null;
		}

		private static GameObject FindByName(string name)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == name)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}

		private static Material FindMaterial(string name)
		{
			Material[] array = Resources.FindObjectsOfTypeAll<Material>();
			Material[] array2 = array;
			foreach (Material val in array2)
			{
				if ((Object)(object)val != (Object)null && ((Object)val).name == name)
				{
					return val;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(Campfire), "Update")]
	internal static class CampfireGlowPatch
	{
		private static void Postfix(Campfire __instance)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0065: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			bool flag = (int)__instance.state == 1;
			bool flag2 = flag;
			Transform val = ((Component)__instance).transform.Find("TT_CampfireGlow");
			if ((Object)(object)val == (Object)null && flag2)
			{
				GameObject val2 = new GameObject("TT_CampfireGlow");
				val2.transform.SetParent(((Component)__instance).transform, false);
				val2.transform.localPosition = new Vector3(0f, 2f, 0f);
				Light val3 = val2.AddComponent<Light>();
				val3.type = (LightType)2;
				val3.color = new Color(1f, 0.6f, 0f, 1f);
				val3.range = 15f;
				val3.shadows = (LightShadows)2;
				val3.intensity = 9f;
				UniversalAdditionalLightData val4 = val2.AddComponent<UniversalAdditionalLightData>();
				val4.usePipelineSettings = true;
				val4.softShadowQuality = (SoftShadowQuality)0;
				AdvancedLightFlicker advancedLightFlicker = val2.AddComponent<AdvancedLightFlicker>();
				advancedLightFlicker.Init(10f, val2.transform.localPosition);
			}
			else if ((Object)(object)val != (Object)null)
			{
				Light component = ((Component)val).GetComponent<Light>();
				if ((Object)(object)component != (Object)null)
				{
					((Behaviour)component).enabled = flag2;
				}
			}
		}
	}
	[HarmonyPatch(typeof(Candle), "Update")]
	internal static class CandleFixPatch
	{
		private static readonly Color PurpleColor = new Color(0.6f, 0.1f, 1f);

		private static void Postfix(Candle __instance)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.ItemLight.Value)
			{
				Transform val = (((Object)(object)__instance.fireParticle != (Object)null) ? ((Component)__instance.fireParticle).transform : ((Component)__instance).transform);
				Light val2 = ((Component)val).GetComponent<Light>();
				if ((Object)(object)val2 == (Object)null)
				{
					val2 = ((Component)val).gameObject.AddComponent<Light>();
					val2.type = (LightType)2;
					val2.color = PurpleColor;
					val2.intensity = 6f;
					val2.range = 18f;
					val2.shadows = (LightShadows)2;
					val2.shadowStrength = 0.85f;
					UniversalAdditionalLightData val3 = ((Component)val).gameObject.AddComponent<UniversalAdditionalLightData>();
					val3.usePipelineSettings = true;
					val3.softShadowQuality = (SoftShadowQuality)0;
				}
				bool flag = (((Behaviour)val2).enabled = (Object)(object)__instance.awakeField != (Object)null && __instance.awakeField.activeSelf);
				val2.intensity = (flag ? 6f : 0f);
			}
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Update")]
	internal static class EternalPeak
	{
		private const float LOCKED_TIME = 23.5f;

		[HarmonyPrefix]
		private static bool Prefix(DayNightManager __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)BiomeMoonManager.GetCurrentBiome() != 5)
			{
				return true;
			}
			__instance.HazeDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)0));
			__instance.RimFresnelDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)1));
			__instance.LavaAlphaDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)2));
			__instance.BandFogDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)3));
			__instance.SunSizeDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)4));
			__instance.timeOfDay = 23.5f;
			if (PhotonNetwork.IsMasterClient)
			{
				__instance.syncTimer += Time.deltaTime;
				if (__instance.syncTimer > 5f)
				{
					PhotonView value = Traverse.Create((object)__instance).Field("photonView").GetValue<PhotonView>();
					if ((Object)(object)value != (Object)null)
					{
						value.RPC("RPCA_SyncTime", (RpcTarget)0, new object[2] { __instance.dayCount, __instance.timeOfDay });
					}
					__instance.syncTimer = 0f;
				}
			}
			__instance.UpdateCycle();
			return false;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class EternalTemple_Start
	{
		private const string TEMPLE_SPECIAL_DAY_PATH = "Map/Biome_4/Gloom/Gloom Temple/SpecialDay Temple";

		[HarmonyPostfix]
		private static void Postfix()
		{
			NeutralizeTempleSpecialDay();
		}

		private static void NeutralizeTempleSpecialDay()
		{
			GameObject val = GameObject.Find("Map/Biome_4/Gloom/Gloom Temple/SpecialDay Temple");
			if ((Object)(object)val == (Object)null)
			{
				Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
				Transform[] array2 = array;
				foreach (Transform val2 in array2)
				{
					if (((Object)val2).name == "SpecialDay Temple")
					{
						val = ((Component)val2).gameObject;
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[EternalTemple] 'SpecialDay Temple' not found — nothing to neutralize");
				return;
			}
			SpecialDayZone component = val.GetComponent<SpecialDayZone>();
			if ((Object)(object)component == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[EternalTemple] 'SpecialDay Temple' has no SpecialDayZone component");
				return;
			}
			component.daylLightIntensity = 0f;
			component.nightLightIntensity = 0f;
			if ((Object)(object)component.specialLight != (Object)null)
			{
				((Behaviour)component.specialLight).enabled = false;
				component.specialLight = null;
			}
			Plugin.Log.LogInfo((object)"[EternalTemple] Neutralized 'SpecialDay Temple' SpecialDayZone");
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Update")]
	internal static class EternalTemple_Update
	{
		private const float LOCKED_TIME = 23.5f;

		[HarmonyPrefix]
		private static bool Prefix(DayNightManager __instance)
		{
			if (BiomeMoonManager.GetCurrentBiomeKey() != "THE CITADEL")
			{
				return true;
			}
			__instance.HazeDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)0));
			__instance.RimFresnelDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)1));
			__instance.LavaAlphaDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)2));
			__instance.BandFogDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)3));
			__instance.SunSizeDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)4));
			__instance.timeOfDay = 23.5f;
			if (PhotonNetwork.IsMasterClient)
			{
				__instance.syncTimer += Time.deltaTime;
				if (__instance.syncTimer > 5f)
				{
					PhotonView value = Traverse.Create((object)__instance).Field("photonView").GetValue<PhotonView>();
					if ((Object)(object)value != (Object)null)
					{
						value.RPC("RPCA_SyncTime", (RpcTarget)0, new object[2] { __instance.dayCount, __instance.timeOfDay });
					}
					__instance.syncTimer = 0f;
				}
			}
			__instance.UpdateCycle();
			return false;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Update")]
	internal static class EternalVolcano
	{
		private const float LOCKED_TIME = 23.5f;

		[HarmonyPrefix]
		private static bool Prefix(DayNightManager __instance)
		{
			if (BiomeMoonManager.GetCurrentBiomeKey() != "THE KILN")
			{
				return true;
			}
			__instance.HazeDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)0));
			__instance.RimFresnelDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)1));
			__instance.LavaAlphaDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)2));
			__instance.BandFogDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)3));
			__instance.SunSizeDebug = Shader.GetGlobalFloat(__instance.getShaderValue((ShaderParams)4));
			__instance.timeOfDay = 23.5f;
			if (PhotonNetwork.IsMasterClient)
			{
				__instance.syncTimer += Time.deltaTime;
				if (__instance.syncTimer > 5f)
				{
					PhotonView value = Traverse.Create((object)__instance).Field("photonView").GetValue<PhotonView>();
					if ((Object)(object)value != (Object)null)
					{
						value.RPC("RPCA_SyncTime", (RpcTarget)0, new object[2] { __instance.dayCount, __instance.timeOfDay });
					}
					__instance.syncTimer = 0f;
				}
			}
			__instance.UpdateCycle();
			return false;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class FinalSceneFix
	{
		private static readonly Color FinalSunColor = new Color(0.6695f, 0.4248f, 0.7717f, 1f);

		private const float NightIntensity = 3f;

		private const float DayIntensity = 3f;

		[HarmonyPostfix]
		private static void Postfix()
		{
			FixFinalCutscenePeak();
		}

		private static void FixFinalCutscenePeak()
		{
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("SpecialDay Peak FinalCutscene");
			if ((Object)(object)val == (Object)null)
			{
				val = FindByName("SpecialDay Peak FinalCutscene");
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[FinalSceneFix] Could not find 'SpecialDay Peak FinalCutscene'");
				return;
			}
			Transform val2 = val.transform.Find("Directional Light");
			if ((Object)(object)val2 == (Object)null)
			{
				Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
				foreach (Transform val3 in componentsInChildren)
				{
					if (((Object)val3).name == "Directional Light")
					{
						val2 = val3;
						break;
					}
				}
			}
			if ((Object)(object)val2 != (Object)null)
			{
				Light component = ((Component)val2).GetComponent<Light>();
				if ((Object)(object)component != (Object)null)
				{
					component.shadows = (LightShadows)2;
					Plugin.Log.LogInfo((object)"[FinalSceneFix] FinalCutscene Directional Light → Soft shadows");
				}
				else
				{
					Plugin.Log.LogWarning((object)"[FinalSceneFix] 'Directional Light' has no Light component");
				}
			}
			else
			{
				Plugin.Log.LogWarning((object)"[FinalSceneFix] Could not find 'Directional Light' child");
			}
			SpecialDayZone component2 = val.GetComponent<SpecialDayZone>();
			if ((Object)(object)component2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[FinalSceneFix] 'SpecialDay Peak FinalCutscene' has no SpecialDayZone component");
				return;
			}
			component2.specialSunColor = FinalSunColor;
			component2.nightLightIntensity = 3f;
			component2.daylLightIntensity = 3f;
			Plugin.Log.LogInfo((object)($"[FinalSceneFix] specialSunColor = {FinalSunColor}, " + $"night={3f}, day={3f}"));
		}

		private static GameObject FindByName(string name)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == name)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}
	}
	public class FlareLightFlicker : MonoBehaviour
	{
		private Light _light;

		private ParticleSystem _particleSystem;

		private Transform _lightTransform;

		private float _baseIntensity;

		private float _seed;

		public void Init(Light light, ParticleSystem particleSystem, float baseIntensity)
		{
			_light = light;
			_lightTransform = ((Component)light).transform;
			_particleSystem = particleSystem;
			_baseIntensity = baseIntensity;
			_seed = Random.Range(0f, 1000f);
		}

		private void Update()
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_light) && Object.op_Implicit((Object)(object)_particleSystem))
			{
				bool isEmitting = _particleSystem.isEmitting;
				if (((Behaviour)_light).enabled != isEmitting)
				{
					((Behaviour)_light).enabled = isEmitting;
				}
				if (((Behaviour)_light).enabled)
				{
					float num = Time.time * 35f + _seed;
					float num2 = Time.time * 65f + _seed;
					float num3 = Mathf.PerlinNoise(num, 0f);
					_light.intensity = _baseIntensity * Mathf.Lerp(0.4f, 1.3f, num3);
					float num4 = (Mathf.PerlinNoise(num2, 10f) - 0.5f) * 0.12f;
					float num5 = (Mathf.PerlinNoise(num2, 20f) - 0.5f) * 0.12f;
					float num6 = (Mathf.PerlinNoise(num2, 30f) - 0.5f) * 0.12f;
					_lightTransform.localPosition = new Vector3(num4, num5, num6);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Flare), "EnableFlareVisuals")]
	internal static class Flare_EnableFlareVisuals_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(Flare __instance)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.ItemLight.Value)
			{
				return;
			}
			ParticleSystem[] array = Object.FindObjectsByType<ParticleSystem>((FindObjectsSortMode)0);
			ParticleSystem[] array2 = array;
			foreach (ParticleSystem val in array2)
			{
				if (!((Object)((Component)val).gameObject).name.Contains("Particle System") || !((Object)(object)((Component)val).transform.parent != (Object)null) || !((Object)((Component)val).transform.parent).name.Contains("VFX_FlareSmoke"))
				{
					continue;
				}
				GameObject gameObject = ((Component)val).gameObject;
				if (!((Object)(object)gameObject.GetComponent<FlareLightFlicker>() != (Object)null))
				{
					GameObject val2 = new GameObject("FlareLightSource");
					val2.transform.SetParent(gameObject.transform, false);
					Light val3 = val2.AddComponent<Light>();
					val2.AddComponent<UniversalAdditionalLightData>();
					val3.type = (LightType)2;
					val3.intensity = 8f;
					val3.range = 16f;
					val3.shadows = (LightShadows)2;
					Color flareColor = __instance.flareColor;
					if (flareColor != Color.clear)
					{
						val3.color = flareColor;
					}
					((Behaviour)val3).enabled = val.isEmitting;
					FlareLightFlicker flareLightFlicker = gameObject.AddComponent<FlareLightFlicker>();
					flareLightFlicker.Init(val3, val, 12f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(Jetpack), "Update")]
	internal static class JetpackFixPatch
	{
		private static readonly Color BlueColor = new Color(0.3f, 0.6f, 1f, 1f);

		private static readonly Vector3 ThrusterOffset = new Vector3(0f, -0.4f, 0f);

		private static void Postfix(Jetpack __instance)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_0090: 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)
			if (Plugin.ItemLight.Value)
			{
				bool value = Traverse.Create((object)__instance).Field("_active").GetValue<bool>();
				Transform val = (((Object)(object)__instance.jetpackParticles != (Object)null) ? ((Component)__instance.jetpackParticles).transform : ((Component)__instance).transform);
				Transform val2 = val.Find("JetpackThrusterLight");
				Light val4;
				if ((Object)(object)val2 == (Object)null)
				{
					GameObject val3 = new GameObject("JetpackThrusterLight");
					val3.transform.SetParent(val, false);
					val3.transform.localPosition = ThrusterOffset;
					val4 = val3.AddComponent<Light>();
					val4.type = (LightType)2;
					val4.color = BlueColor;
					val4.intensity = 8f;
					val4.range = 3f;
					val4.shadows = (LightShadows)0;
					val4.shadowStrength = 0.85f;
					UniversalAdditionalLightData val5 = val3.AddComponent<UniversalAdditionalLightData>();
					val5.usePipelineSettings = true;
					val5.softShadowQuality = (SoftShadowQuality)0;
				}
				else
				{
					val4 = ((Component)val2).GetComponent<Light>();
				}
				if ((Object)(object)val4 != (Object)null)
				{
					((Behaviour)val4).enabled = value;
					val4.intensity = (value ? 8f : 0f);
				}
			}
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class LavaBubblesOnPlane
	{
		private const string LAVA_BUBBLES_PATH = "Map/Biome_4/Caldera/Volcano/Caldera_Segment/Lava Bubbles";

		private const string BUBBLES_CHILD_NAME = "Bubbles";

		private const string PLANE_PATH = "Map/Biome_4/Caldera/Volcano/Volcano_Segment/Mechanics/RisingLava/Lava/Plane";

		private const string CLONE_NAME = "TT_LavaBubblesOnPlane";

		[HarmonyPostfix]
		private static void Postfix()
		{
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Map/Biome_4/Caldera/Volcano/Caldera_Segment/Lava Bubbles");
			if ((Object)(object)val == (Object)null)
			{
				val = FindByName("Lava Bubbles");
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[LavaBubblesOnPlane] Source 'Lava Bubbles' not found");
				return;
			}
			Transform val2 = val.transform.Find("Bubbles");
			if ((Object)(object)val2 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[LavaBubblesOnPlane] Source 'Bubbles' child not found");
				return;
			}
			GameObject val3 = GameObject.Find("Map/Biome_4/Caldera/Volcano/Volcano_Segment/Mechanics/RisingLava/Lava/Plane");
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = FindByParentChain("Plane", new string[2] { "RisingLava", "Lava" });
			}
			if ((Object)(object)val3 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[LavaBubblesOnPlane] Destination 'Plane' not found");
				return;
			}
			if ((Object)(object)val3.transform.Find("TT_LavaBubblesOnPlane") != (Object)null)
			{
				Plugin.Log.LogInfo((object)"[LavaBubblesOnPlane] Clone already present on Plane — skipping");
				return;
			}
			GameObject val4 = Object.Instantiate<GameObject>(((Component)val2).gameObject);
			((Object)val4).name = "TT_LavaBubblesOnPlane";
			val4.transform.SetParent(val3.transform, false);
			val4.transform.localPosition = new Vector3(0f, 0f, 0f);
			val4.transform.localRotation = Quaternion.identity;
			val4.transform.localScale = new Vector3(1f, 1f, 1f);
			val4.SetActive(true);
			ParticleSystem component = val4.GetComponent<ParticleSystem>();
			if ((Object)(object)component != (Object)null)
			{
				component.playbackSpeed = 1.6f;
				MainModule main = component.main;
				((MainModule)(ref main)).maxParticles = 60;
				ShapeModule shape = component.shape;
				((ShapeModule)(ref shape)).scale = new Vector3(66f, 0.5f, 66f);
				Plugin.Log.LogInfo((object)("[LavaBubblesOnPlane] Attached clone to " + GetPath(val3.transform) + " " + $"at world pos {val4.transform.position}"));
			}
			else
			{
				Plugin.Log.LogWarning((object)"[LavaBubblesOnPlane] Clone has no ParticleSystem");
			}
		}

		private static GameObject FindByName(string name)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == name)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}

		private static GameObject FindByParentChain(string name, string[] requiredAncestorNames)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name != name)
				{
					continue;
				}
				bool flag = true;
				foreach (string text in requiredAncestorNames)
				{
					bool flag2 = false;
					Transform parent = val.parent;
					while ((Object)(object)parent != (Object)null)
					{
						if (((Object)parent).name == text)
						{
							flag2 = true;
							break;
						}
						parent = parent.parent;
					}
					if (!flag2)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}

		private static string GetPath(Transform t)
		{
			string text = ((Object)t).name;
			while ((Object)(object)t.parent != (Object)null)
			{
				t = t.parent;
				text = ((Object)t).name + "/" + text;
			}
			return text;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class KilnFix
	{
		private const float LightIntensity = 12f;

		private const float LightRange = 60f;

		private static readonly Color LightColor = new Color(1f, 0.4906f, 0.08f, 1f);

		[HarmonyPostfix]
		private static void Postfix()
		{
			if (Plugin.KilnTweak.Value)
			{
				AttachLavaLight();
				MoveVolcanoSmoke();
			}
		}

		private static void AttachLavaLight()
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Mechanics/RisingLava/Lava/Plane");
			if ((Object)(object)val == (Object)null)
			{
				val = GameObject.Find("Map/Mechanics/RisingLava/Lava/Plane");
			}
			if ((Object)(object)val == (Object)null)
			{
				val = FindByParentChain("Plane", new string[2] { "RisingLava", "Lava" });
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[KilnLavaLight] Could not find Mechanics/RisingLava/Lava/Plane");
			}
			else if ((Object)(object)val.GetComponent<Light>() == (Object)null)
			{
				Light val2 = val.AddComponent<Light>();
				val2.type = (LightType)2;
				val2.intensity = 12f;
				val2.range = 60f;
				val2.shadows = (LightShadows)2;
				val2.color = LightColor;
				UniversalAdditionalLightData val3 = val.AddComponent<UniversalAdditionalLightData>();
				val3.usePipelineSettings = true;
				val3.softShadowQuality = (SoftShadowQuality)0;
				Plugin.Log.LogInfo((object)("[KilnLavaLight] Attached lava light to " + GetPath(val.transform)));
			}
		}

		private static void MoveVolcanoSmoke()
		{
			GameObject val = GameObject.Find("Map/Biome_4/Caldera/Volcano/Caldera_Segment/volcano Smoke");
			if ((Object)(object)val == (Object)null)
			{
				Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
				Transform[] array2 = array;
				foreach (Transform val2 in array2)
				{
					if (((Object)val2).name == "volcano smoke")
					{
						val = ((Component)val2).gameObject;
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[KilnLavaLight] Could not find 'volcano smoke'");
				return;
			}
			GameObject val3 = GameObject.Find("Map/Biome_4/Caldera/Volcano/Volcano_Segment");
			if ((Object)(object)val3 == (Object)null)
			{
				Transform[] array3 = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
				Transform[] array4 = array3;
				foreach (Transform val4 in array4)
				{
					if (((Object)val4).name == "Volcano_Segment")
					{
						val3 = ((Component)val4).gameObject;
						break;
					}
				}
			}
			if ((Object)(object)val3 == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[KilnLavaLight] Could not find 'Volcano_Segment' destination");
				return;
			}
			val.transform.SetParent(val3.transform, true);
			Plugin.Log.LogInfo((object)("[KilnLavaLight] Moved 'volcano smoke' to " + GetPath(val3.transform)));
		}

		private static GameObject FindByParentChain(string name, string[] requiredAncestorNames)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name != name)
				{
					continue;
				}
				bool flag = true;
				foreach (string text in requiredAncestorNames)
				{
					bool flag2 = false;
					Transform parent = val.parent;
					while ((Object)(object)parent != (Object)null)
					{
						if (((Object)parent).name == text)
						{
							flag2 = true;
							break;
						}
						parent = parent.parent;
					}
					if (!flag2)
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}

		private static string GetPath(Transform t)
		{
			string text = ((Object)t).name;
			while ((Object)(object)t.parent != (Object)null)
			{
				t = t.parent;
				text = ((Object)t).name + "/" + text;
			}
			return text;
		}
	}
	[HarmonyPatch(typeof(Lantern))]
	internal static class LanternFixPatch
	{
		private const float DefaultLanternIntensity = 10f;

		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void FixFaerieLanternOnAwake(Lantern __instance)
		{
			if (__instance.lightIntensity <= 0f)
			{
				__instance.lightIntensity = 10f;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void FixFaerieLanternAndUpdateLight(Lantern __instance)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Invalid comparison between Unknown and I4
			if (Plugin.ItemLight.Value && !((Object)(object)__instance.lanternLight == (Object)null))
			{
				Light lanternLight = __instance.lanternLight;
				if (((Component)lanternLight).gameObject.activeSelf && lanternLight.intensity <= 0.01f)
				{
					__instance.lightIntensity = 10f;
					lanternLight.intensity = 10f;
				}
				if ((int)lanternLight.shadows == 0)
				{
					lanternLight.shadows = (LightShadows)2;
					lanternLight.shadowStrength = 0.85f;
					lanternLight.shadowBias = 0.05f;
					lanternLight.shadowNormalBias = 0.4f;
					lanternLight.range = 16f;
				}
				UniversalAdditionalLightData val = ((Component)lanternLight).GetComponent<UniversalAdditionalLightData>();
				if ((Object)(object)val == (Object)null)
				{
					val = ((Component)lanternLight).gameObject.AddComponent<UniversalAdditionalLightData>();
				}
				if ((Object)(object)val != (Object)null && !val.usePipelineSettings)
				{
					val.usePipelineSettings = true;
					val.softShadowQuality = (SoftShadowQuality)0;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerTrackParticles), "Start")]
	internal static class LavaBubblesYTrackPatch
	{
		private const string LAVA_BUBBLES_OBJ_NAME = "Lava Bubbles";

		private const string RIVER_OBJ_NAME = "River";

		private const float BUBBLE_Y_OFFSET = 13f;

		private static Transform _riverTransform;

		[HarmonyPostfix]
		private static void Postfix(PlayerTrackParticles __instance)
		{
			if (!(((Object)((Component)__instance).gameObject).name != "Lava Bubbles"))
			{
				_riverTransform = FindRiver(((Component)__instance).transform);
				if ((Object)(object)_riverTransform == (Object)null)
				{
					Plugin.Log.LogWarning((object)"[LavaBubbles] Could not find 'River' transform");
				}
				else if ((Object)(object)((Component)__instance).gameObject.GetComponent<LavaBubblesYTracker>() == (Object)null)
				{
					LavaBubblesYTracker lavaBubblesYTracker = ((Component)__instance).gameObject.AddComponent<LavaBubblesYTracker>();
					lavaBubblesYTracker.Init(_riverTransform, 13f);
					Plugin.Log.LogInfo((object)"[LavaBubbles] Y-tracking attached to 'Lava Bubbles'");
				}
			}
		}

		private static Transform FindRiver(Transform bubbles)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Transform val = bubbles;
			while ((Object)(object)val != (Object)null && ((Object)val).name != "Caldera_Segment")
			{
				val = val.parent;
			}
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Transform val2 = val.Find("River");
			if ((Object)(object)val2 != (Object)null)
			{
				return val2;
			}
			foreach (Transform item in val)
			{
				Transform val3 = item;
				if (((Object)val3).name.StartsWith("River"))
				{
					return val3;
				}
			}
			return null;
		}
	}
	internal class LavaBubblesYTracker : MonoBehaviour
	{
		private Transform _source;

		private float _offset;

		public void Init(Transform source, float offset)
		{
			_source = source;
			_offset = offset;
		}

		private void LateUpdate()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_source == (Object)null))
			{
				Vector3 position = ((Component)this).transform.position;
				float num = _source.position.y + _offset;
				if (position.y != num)
				{
					position.y = num;
					((Component)this).transform.position = position;
				}
			}
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class LavaBubblesSceneSetup
	{
		private const string BUBBLES_CHILD_NAME = "Bubbles";

		private const float BUBBLES_PLAYBACK_SPEED = 1.5f;

		private const int BUBBLES_MAX_PARTICLES = 60;

		[HarmonyPostfix]
		private static void Postfix()
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Map/Biome_4/Caldera/Volcano/Caldera_Segment/Lava Bubbles");
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			if (!val.activeSelf)
			{
				val.SetActive(true);
			}
			PlayerTrackParticles component = val.GetComponent<PlayerTrackParticles>();
			if ((Object)(object)component != (Object)null && !((Behaviour)component).enabled)
			{
				((Behaviour)component).enabled = true;
			}
			Transform val2 = val.transform.Find("Bubbles");
			if (!((Object)(object)val2 == (Object)null))
			{
				if (!((Component)val2).gameObject.activeSelf)
				{
					((Component)val2).gameObject.SetActive(true);
				}
				ParticleSystem component2 = ((Component)val2).GetComponent<ParticleSystem>();
				if (!((Object)(object)component2 == (Object)null))
				{
					MainModule main = component2.main;
					((MainModule)(ref main)).simulationSpeed = 1.5f;
					((MainModule)(ref main)).maxParticles = 60;
				}
			}
		}

		private static GameObject FindByName(string name)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == name)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "UpdateCycle")]
	internal static class DayNightManager_UpdateCycle_Patch
	{
		[HarmonyPostfix]
		private static void Postfix(DayNightManager __instance)
		{
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.MoonLightEnable.Value || (Object)(object)__instance.moon == (Object)null || (Object)(object)__instance.sun == (Object)null)
			{
				return;
			}
			Light moon = __instance.moon;
			Light sun = __instance.sun;
			Transform transform = ((Component)moon).transform;
			Transform transform2 = ((Component)sun).transform;
			if ((Object)(object)__instance.earth != (Object)null && (Object)(object)transform.parent != (Object)(object)__instance.earth)
			{
				transform.SetParent(__instance.earth, false);
			}
			if (transform.localPosition != Vector3.zero)
			{
				transform.localPosition = Vector3.zero;
			}
			if (transform.localRotation != transform2.localRotation)
			{
				transform.localRotation = transform2.localRotation;
			}
			BiomeMoonManager.UpdateCurrentBiome();
			float timeOfDayNormalized = __instance.timeOfDayNormalized;
			Color moonColor = BiomeMoonManager.GetMoonColor(timeOfDayNormalized, sun.color);
			if (moon.color != moonColor)
			{
				moon.color = moonColor;
			}
			if (((Behaviour)moon).enabled)
			{
				float moonIntensity = BiomeMoonManager.GetMoonIntensity(timeOfDayNormalized);
				if (moon.intensity != moonIntensity)
				{
					moon.intensity = moonIntensity;
				}
				moon.shadowStrength = 1f;
				moon.shadows = (LightShadows)2;
				moon.shadowCustomResolution = -1;
				moon.renderingLayerMask = 1;
				moon.range = 10f;
			}
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class NadirFix
	{
		private static readonly Color VoidSpecialSunColor = new Color(0.5f, 0.5f, 0.5f, 1f);

		private static readonly Color PeakGateMoonColor = new Color(1f, 0.6016f, 0.3f, 1f);

		private const float PeakGateMoonIntensity = 12f;

		private const float PeakGateMoonRange = 20f;

		[HarmonyPostfix]
		private static void Postfix()
		{
			FixVoidSpecialDay();
			FixPeakGateMoon();
		}

		private static void FixVoidSpecialDay()
		{
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.Find("Void special day");
			if ((Object)(object)val == (Object)null)
			{
				val = FindByName("Void special day");
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform val2 = val.transform.Find("Directional Light");
			if ((Object)(object)val2 == (Object)null)
			{
				Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
				foreach (Transform val3 in componentsInChildren)
				{
					if (((Object)val3).name == "Directional Light")
					{
						val2 = val3;
						break;
					}
				}
			}
			if ((Object)(object)val2 != (Object)null)
			{
				Light component = ((Component)val2).GetComponent<Light>();
				if ((Object)(object)component != (Object)null)
				{
					component.shadows = (LightShadows)2;
				}
			}
			SpecialDayZone component2 = val.GetComponent<SpecialDayZone>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.specialSunColor = VoidSpecialSunColor;
			}
		}

		private static void FixPeakGateMoon()
		{
			//IL_0098: 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)
			GameObject val = GameObject.Find("Peak Gate Moon");
			if ((Object)(object)val == (Object)null)
			{
				val = FindByName("Peak Gate Moon");
			}
			if (!((Object)(object)val == (Object)null))
			{
				Light component = val.GetComponent<Light>();
				if ((Object)(object)component == (Object)null)
				{
					component = val.AddComponent<Light>();
					component.type = (LightType)2;
					component.shadows = (LightShadows)2;
					component.color = PeakGateMoonColor;
					component.intensity = 12f;
					component.range = 20f;
				}
				else
				{
					component.type = (LightType)2;
					component.shadows = (LightShadows)2;
					component.color = PeakGateMoonColor;
					component.intensity = 12f;
					component.range = 20f;
				}
				if ((Object)(object)val.GetComponent<UniversalAdditionalLightData>() == (Object)null)
				{
					UniversalAdditionalLightData val2 = val.AddComponent<UniversalAdditionalLightData>();
					val2.usePipelineSettings = true;
					val2.softShadowQuality = (SoftShadowQuality)0;
				}
			}
		}

		private static GameObject FindByName(string name)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == name)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}
	}
	[HarmonyPatch(typeof(SFX_PlayOneShot))]
	internal static class NapBerryLightPatch
	{
		private class NapBerryLightController : MonoBehaviour
		{
			private Light _light;

			private float _phaseTimer;

			private const float Frequency = 4f;

			private void Awake()
			{
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				_light = ((Component)this).gameObject.GetComponent<Light>();
				if ((Object)(object)_light == (Object)null)
				{
					_light = ((Component)this).gameObject.AddComponent<Light>();
					_light.type = (LightType)2;
					_light.color = LightColor;
					_light.range = 15f;
					_light.shadows = (LightShadows)2;
					_light.shadowStrength = 0.85f;
					UniversalAdditionalLightData val = ((Component)this).gameObject.AddComponent<UniversalAdditionalLightData>();
					val.usePipelineSettings = true;
					val.softShadowQuality = (SoftShadowQuality)0;
				}
				if ((Object)(object)_light != (Object)null)
				{
					((Behaviour)_light).enabled = true;
				}
			}

			private void Update()
			{
				if (Plugin.ItemLight.Value && !((Object)(object)_light == (Object)null))
				{
					if (!((Behaviour)_light).enabled)
					{
						((Behaviour)_light).enabled = true;
					}
					_phaseTimer += Time.deltaTime * 4f;
					float t = _phaseTimer / (MathF.PI * 2f) % 1f;
					float num = CalculateLeftSkewedSine(t);
					_light.intensity = 6f * num;
				}
			}

			private float CalculateLeftSkewedSine(float t)
			{
				if (t < 0.25f)
				{
					float num = t / 0.25f;
					return num * num * (3f - 2f * num);
				}
				float num2 = (t - 0.25f) / 0.75f;
				return Mathf.Pow(1f - num2, 2f);
			}
		}

		[HarmonyPatch(typeof(Item), "Awake")]
		internal static class NapBerryCloneLightPatch
		{
			private const string NamePrefix = "napberry";

			[HarmonyPostfix]
			private static void Postfix(Item __instance)
			{
				if (!Plugin.ItemLight.Value || (Object)(object)__instance == (Object)null)
				{
					return;
				}
				GameObject gameObject = ((Component)__instance).gameObject;
				if (!((Object)(object)gameObject == (Object)null) && ((Object)gameObject).name.StartsWith("napberry", StringComparison.OrdinalIgnoreCase))
				{
					PhotonView component = gameObject.GetComponent<PhotonView>();
					if (!((Object)(object)component == (Object)null) && component.isRuntimeInstantiated)
					{
						AttachLight(gameObject);
					}
				}
			}

			private static void AttachLight(GameObject go)
			{
				if (!((Object)(object)go.GetComponent<NapBerryCloneLightController>() != (Object)null))
				{
					go.AddComponent<NapBerryCloneLightController>();
					Plugin.Log.LogInfo((object)("[NapBerry] Attached clone light to " + ((Object)go).name));
				}
			}
		}

		internal class NapBerryCloneLightController : MonoBehaviour
		{
			private static readonly Color LightColor = new Color(0.9128f, 0.3774f, 1f, 1f);

			private const float Intensity = 3f;

			private const float Range = 3f;

			private void Awake()
			{
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				Light component = ((Component)this).gameObject.GetComponent<Light>();
				if ((Object)(object)component == (Object)null)
				{
					component = ((Component)this).gameObject.AddComponent<Light>();
					component.type = (LightType)2;
					component.color = LightColor;
					component.intensity = 3f;
					component.range = 3f;
					component.shadows = (LightShadows)0;
					((Behaviour)component).enabled = true;
				}
			}
		}

		private static readonly Color LightColor = new Color(0.9128f, 0.3774f, 1f, 1f);

		private const float MaxIntensity = 6f;

		private const float LightRange = 15f;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void AttachToFakeNapBerry(SFX_PlayOneShot __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)((Component)__instance).transform.parent == (Object)null)
			{
				return;
			}
			Transform parent = ((Component)__instance).transform.parent;
			if (!(((Object)parent).name == "Pivot"))
			{
				return;
			}
			Transform val = parent.Find("FakeNapBerry");
			if ((Object)(object)val != (Object)null)
			{
				GameObject gameObject = ((Component)val).gameObject;
				if ((Object)(object)gameObject.GetComponent<NapBerryLightController>() == (Object)null)
				{
					gameObject.AddComponent<NapBerryLightController>();
				}
			}
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class PeakFix
	{
		private const float LightIntensity = 12f;

		private const float RimFresnelValue = 0.2f;

		[HarmonyPostfix]
		private static void Postfix()
		{
			FixSpecialDayPeak();
		}

		private static void FixSpecialDayPeak()
		{
			GameObject val = GameObject.Find("Map/Biome_4/Caldera/Volcano/Volcano_Segment/Peak_Kiln Variant/SpecialDay Peak");
			if ((Object)(object)val == (Object)null)
			{
				val = FindByName("SpecialDay Peak");
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)"[PeakFix] Could not find 'SpecialDay Peak'");
				return;
			}
			Transform val2 = val.transform.Find("Directional Light");
			if ((Object)(object)val2 == (Object)null)
			{
				Transform[] componentsInChildren = val.GetComponentsInChildren<Transform>(true);
				foreach (Transform val3 in componentsInChildren)
				{
					if (((Object)val3).name == "Directional Light")
					{
						val2 = val3;
						break;
					}
				}
			}
			if ((Object)(object)val2 != (Object)null)
			{
				Light component = ((Component)val2).GetComponent<Light>();
				if ((Object)(object)component != (Object)null)
				{
					component.intensity = 12f;
					component.shadows = (LightShadows)2;
				}
			}
			SpecialDayZone component2 = val.GetComponent<SpecialDayZone>();
			if (!((Object)(object)component2 == (Object)null) && component2.globalShaderVals != null && component2.globalShaderVals.Length >= 2)
			{
				ShaderVal val4 = component2.globalShaderVals[1];
				val4.value = 0.2f;
				component2.globalShaderVals[1] = val4;
			}
		}

		private static GameObject FindByName(string name)
		{
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == name)
				{
					return ((Component)val).gameObject;
				}
			}
			return null;
		}
	}
	internal static class TechnicalTweaksHelper
	{
		internal const float DuskStart = 0.708f;

		internal const float NightStart = 0.875f;

		internal const float PeakStart = 0.916f;

		internal const float PeakEnd = 0.083f;

		internal const float NightEnd = 0.166f;

		internal const float DawnStart = 0.208f;

		public static readonly Color DEFAULT_MOON_START = new Color(0.15f, 0.09f, 0.2f, 0.15f);

		public static readonly Color DEFAULT_MOON_MID = new Color(0.15f, 0.76f, 1f, 1f);

		public static readonly Color DEFAULT_MOON_END = new Color(0.15f, 0.09f, 0.2f, 0.15f);

		public static float SmoothStep(float edge0, float edge1, float x)
		{
			if (edge0 == edge1)
			{
				return (x < edge0) ? 0f : 1f;
			}
			float num = (x - edge0) / (edge1 - edge0);
			num = Mathf.Clamp01(num);
			return num * num * (3f - 2f * num);
		}

		public static Color ParseColor(string colorString)
		{
			//IL_0059: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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)
			string[] array = colorString.Split(',');
			if (array.Length >= 4)
			{
				float num = float.Parse(array[0].Trim());
				float num2 = float.Parse(array[1].Trim());
				float num3 = float.Parse(array[2].Trim());
				float num4 = float.Parse(array[3].Trim());
				return new Color(num, num2, num3, num4);
			}
			if (array.Length >= 3)
			{
				float num5 = float.Parse(array[0].Trim());
				float num6 = float.Parse(array[1].Trim());
				float num7 = float.Parse(array[2].Trim());
				return new Color(num5, num6, num7, 1f);
			}
			return Color.white;
		}
	}
	[HarmonyPatch(typeof(DayNightManager), "Start")]
	internal static class Crucible_Patch
	{
		private const string TargetName = "Particle System";

		private const string ParentPathSubString = "Crucible";

		[HarmonyPostfix]
		private static void Postfix()
		{
			if (!Plugin.CitadelTweak.Value)
			{
				return;
			}
			Transform[] array = Object.FindObjectsByType<Transform>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			Transform[] array2 = array;
			foreach (Transform val in array2)
			{
				if (((Object)val).name == "Particle System" && GetHierarchyPath(val).Contains("Crucible"))
				{
					SetupCrucible(((Component)val).gameObject);
				}
			}
		}

		private static void SetupCrucible(GameObject go)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)go.GetComponent<Light>() != (Object)null))
			{
				Light val = go.AddComponent<Light>();
				go.AddComponent<UniversalAdditionalLightData>();
				val.type = (LightType)2;
				val.intensity = 5f;
				val.range = 300f;
				val.color = new Color(1f, 0.58f, 0f, 1f);
				val.shadows = (LightShadows)2;
				((Behaviour)val).enabled = true;
			}
		}

		private static string GetHierarchyPath(Transform transform)
		{
			string text = ((Object)transform).name;
			while ((Object)(object)transform.parent != (Object)null)
			{
				transform = transform.parent;
				text = ((Object)transform).name + "/" + text;
			}
			return text;
		}
	}
}