Decompiled source of AlternativeEmeraldSea v1.1.0

BepInEx/plugins/AlternativeEmeraldSea/AlternativeEmeraldSea.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("AlternativeEmeraldSea")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyProduct("AlternativeEmeraldSea")]
[assembly: AssemblyTitle("AlternativeEmeraldSea")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AlternativeEmeraldSea
{
	internal struct EmeraldContribution
	{
		internal float Weight;

		internal Color Water;

		internal Color Surface;

		internal Color Scattering;

		internal Color Fog;

		internal float Temperature;

		internal float Tint;

		internal float Specular;

		internal Color SkyTint;

		internal float Atmosphere;

		internal float Exposure;

		internal float SkyTintWeight;

		internal float AtmosphereWeight;

		internal float ExposureWeight;

		private static readonly int SkyTintId = Shader.PropertyToID("_SkyTint");

		private static readonly int AtmosphereId = Shader.PropertyToID("_AtmosphereThickness");

		private static readonly int ExposureId = Shader.PropertyToID("_Exposure");

		internal static EmeraldContribution From(OceanColorPalette day)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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)
			//IL_0036: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			EmeraldContribution result = new EmeraldContribution
			{
				Weight = 1f,
				Water = day.waterColor,
				Surface = day.surfaceColor,
				Scattering = day.scatteringColor,
				Temperature = day.temperature,
				Fog = day.fog,
				Tint = day.tint,
				Specular = day.oceanSpecular
			};
			Material skyMaterial = day.skyMaterial;
			if ((Object)(object)skyMaterial != (Object)null)
			{
				if (skyMaterial.HasProperty(SkyTintId))
				{
					result.SkyTint = skyMaterial.GetColor(SkyTintId);
					result.SkyTintWeight = 1f;
				}
				if (skyMaterial.HasProperty(AtmosphereId))
				{
					result.Atmosphere = skyMaterial.GetFloat(AtmosphereId);
					result.AtmosphereWeight = 1f;
				}
				if (skyMaterial.HasProperty(ExposureId))
				{
					result.Exposure = skyMaterial.GetFloat(ExposureId);
					result.ExposureWeight = 1f;
				}
			}
			return result;
		}

		internal static EmeraldContribution Blend(EmeraldContribution one, EmeraldContribution two, float lerp)
		{
			//IL_0032: 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_003e: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_005c: 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_0068: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00b6: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: 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_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)
			float num = Mathf.Clamp01(lerp);
			float num2 = 1f - num;
			return new EmeraldContribution
			{
				Weight = one.Weight * num2 + two.Weight * num,
				Water = one.Water * num2 + two.Water * num,
				Surface = one.Surface * num2 + two.Surface * num,
				Scattering = one.Scattering * num2 + two.Scattering * num,
				Temperature = one.Temperature * num2 + two.Temperature * num,
				Fog = one.Fog * num2 + two.Fog * num,
				Tint = one.Tint * num2 + two.Tint * num,
				Specular = one.Specular * num2 + two.Specular * num,
				SkyTint = one.SkyTint * num2 + two.SkyTint * num,
				Atmosphere = one.Atmosphere * num2 + two.Atmosphere * num,
				Exposure = one.Exposure * num2 + two.Exposure * num,
				SkyTintWeight = one.SkyTintWeight * num2 + two.SkyTintWeight * num,
				AtmosphereWeight = one.AtmosphereWeight * num2 + two.AtmosphereWeight * num,
				ExposureWeight = one.ExposureWeight * num2 + two.ExposureWeight * num
			};
		}

		internal void ApplySky(Material sky, SeaPreset preset, float day)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)sky == (Object)null))
			{
				if (preset.SkyTint.HasValue && SkyTintWeight > 0f && sky.HasProperty(SkyTintId))
				{
					sky.SetColor(SkyTintId, ReplaceRgb(sky.GetColor(SkyTintId), SkyTint, preset.SkyTint.Value, SkyTintWeight, day));
				}
				if (preset.Atmosphere.HasValue && AtmosphereWeight > 0f && sky.HasProperty(AtmosphereId))
				{
					sky.SetFloat(AtmosphereId, sky.GetFloat(AtmosphereId) + (preset.Atmosphere.Value * AtmosphereWeight - Atmosphere) * day);
				}
				if (preset.Exposure.HasValue && ExposureWeight > 0f && sky.HasProperty(ExposureId))
				{
					sky.SetFloat(ExposureId, sky.GetFloat(ExposureId) + (preset.Exposure.Value * ExposureWeight - Exposure) * day);
				}
			}
		}

		internal static Color ReplaceRgb(Color current, Color weightedOriginal, Color configured, float weight, float day)
		{
			//IL_0009: 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_0026: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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)
			current.r += (configured.r * weight - weightedOriginal.r) * day;
			current.g += (configured.g * weight - weightedOriginal.g) * day;
			current.b += (configured.b * weight - weightedOriginal.b) * day;
			return current;
		}
	}
	internal static class EmeraldRegistry
	{
		private sealed class Entry
		{
			internal EmeraldContribution Value;
		}

		private static ConditionalWeakTable<WeatherSet, Entry> entries = new ConditionalWeakTable<WeatherSet, Entry>();

		internal static void Clear()
		{
			entries = new ConditionalWeakTable<WeatherSet, Entry>();
		}

		internal static EmeraldContribution Get(WeatherSet set)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)set == (Object)null)
			{
				return default(EmeraldContribution);
			}
			if (entries.TryGetValue(set, out var value))
			{
				return value.Value;
			}
			EmeraldContribution emeraldContribution = ((string.Equals(((Object)set).name, "W emerald Clear", StringComparison.OrdinalIgnoreCase) || string.Equals(((Object)set).name, "W emerald Clear(Clone)", StringComparison.OrdinalIgnoreCase)) ? EmeraldContribution.From(set.dayPalette) : default(EmeraldContribution));
			Set(set, emeraldContribution);
			return emeraldContribution;
		}

		internal static void Set(WeatherSet set, EmeraldContribution value)
		{
			if (!((Object)(object)set == (Object)null))
			{
				if (entries.TryGetValue(set, out var value2))
				{
					value2.Value = value;
					return;
				}
				entries.Add(set, new Entry
				{
					Value = value
				});
			}
		}
	}
	[BepInPlugin("DogEggz.AlternativeEmeraldSea", "Alternative Emerald Sea", "1.1.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "DogEggz.AlternativeEmeraldSea";

		public const string Name = "Alternative Emerald Sea";

		public const string Version = "1.1.0";

		private ConfigEntry<bool> presetEnabled;

		private ConfigEntry<bool> caribbeanTurquoise;

		private ConfigEntry<bool> emeraldSea;

		private bool changingSelection;

		private Harmony harmony;

		private readonly ScopedMaterial material = new ScopedMaterial();

		private float scope;

		internal static Plugin Instance { get; private set; }

		private SeaPreset SelectedPreset
		{
			get
			{
				if (caribbeanTurquoise == null || !caribbeanTurquoise.Value)
				{
					if (emeraldSea == null || !emeraldSea.Value)
					{
						return null;
					}
					return SeaPreset.EmeraldSea;
				}
				return SeaPreset.CaribbeanTurquoise;
			}
		}

		internal bool Active
		{
			get
			{
				if (((Behaviour)this).isActiveAndEnabled && presetEnabled != null && presetEnabled.Value)
				{
					return SelectedPreset != null;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Expected O, but got Unknown
			Instance = this;
			presetEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Apply the selected preset to Emerald clear daytime only. Other regions, cloudy/rain/storm weather, dawn/dusk, and night keep their original palettes. Disable Ocean Color Configurator overrides when using this mod.");
			caribbeanTurquoise = ((BaseUnityPlugin)this).Config.Bind<bool>("Presets", "Caribbean Turquoise", true, "Use the saved turquoise water, green surface, reflections, and atmosphere settings. Selecting this turns Emerald Sea off. Both preset toggles off uses the game palette. Tuned at Gamma 1.0.");
			emeraldSea = ((BaseUnityPlugin)this).Config.Bind<bool>("Presets", "Emerald Sea", false, "Use the saved darker emerald water and reflections, with Temperature 15. Selecting this turns Caribbean Turquoise off. Both preset toggles off uses the game palette.");
			if (caribbeanTurquoise.Value && emeraldSea.Value)
			{
				emeraldSea.Value = false;
			}
			presetEnabled.SettingChanged += SettingsChanged;
			caribbeanTurquoise.SettingChanged += SettingsChanged;
			emeraldSea.SettingChanged += SettingsChanged;
			EmeraldRegistry.Clear();
			harmony = new Harmony("DogEggz.AlternativeEmeraldSea");
			harmony.PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Alternative Emerald Sea 1.1.0 loaded: Emerald clear daytime only.");
		}

		private void SettingsChanged(object sender, EventArgs args)
		{
			if (changingSelection)
			{
				return;
			}
			changingSelection = true;
			try
			{
				if (sender == caribbeanTurquoise && caribbeanTurquoise.Value)
				{
					emeraldSea.Value = false;
				}
				else if (sender == emeraldSea && emeraldSea.Value)
				{
					caribbeanTurquoise.Value = false;
				}
				material.ApplyCurrent(Active ? scope : 0f, SelectedPreset);
			}
			finally
			{
				changingSelection = false;
			}
		}

		internal void ApplyPalette(ref OceanColorPalette palette, EmeraldContribution contribution, float dawn, float night)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: 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)
			float num = (1f - Mathf.Clamp01(dawn)) * (1f - Mathf.Clamp01(night));
			scope = Mathf.Clamp01(contribution.Weight) * num;
			if (Active && !(scope <= 0f))
			{
				SeaPreset selectedPreset = SelectedPreset;
				palette.waterColor = EmeraldContribution.ReplaceRgb(palette.waterColor, contribution.Water, selectedPreset.Water, contribution.Weight, num);
				palette.surfaceColor = EmeraldContribution.ReplaceRgb(palette.surfaceColor, contribution.Surface, selectedPreset.Surface, contribution.Weight, num);
				if (selectedPreset.Scattering.HasValue)
				{
					palette.scatteringColor = EmeraldContribution.ReplaceRgb(palette.scatteringColor, contribution.Scattering, selectedPreset.Scattering.Value, contribution.Weight, num);
				}
				if (selectedPreset.Fog.HasValue)
				{
					palette.fog = EmeraldContribution.ReplaceRgb(palette.fog, contribution.Fog, selectedPreset.Fog.Value, contribution.Weight, num);
				}
				palette.temperature += (selectedPreset.Temperature * contribution.Weight - contribution.Temperature) * num;
				if (selectedPreset.Tint.HasValue)
				{
					palette.tint += (selectedPreset.Tint.Value * contribution.Weight - contribution.Tint) * num;
				}
				if (selectedPreset.Specular.HasValue)
				{
					palette.oceanSpecular += (selectedPreset.Specular.Value * contribution.Weight - contribution.Specular) * num;
				}
				contribution.ApplySky(palette.skyMaterial, selectedPreset, num);
			}
		}

		internal void ApplyMaterial(Material ocean)
		{
			material.Apply(ocean, Active ? scope : 0f, SelectedPreset);
		}

		private void OnDisable()
		{
			material.Restore();
		}

		private void OnDestroy()
		{
			if (presetEnabled != null)
			{
				presetEnabled.SettingChanged -= SettingsChanged;
			}
			if (caribbeanTurquoise != null)
			{
				caribbeanTurquoise.SettingChanged -= SettingsChanged;
			}
			if (emeraldSea != null)
			{
				emeraldSea.SettingChanged -= SettingsChanged;
			}
			material.Restore();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			EmeraldRegistry.Clear();
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}
	}
	[HarmonyPatch(typeof(WeatherSet), "BlendSets")]
	internal static class BlendPatch
	{
		internal static void Prefix(WeatherSet setOne, WeatherSet setTwo, float lerp, out EmeraldContribution __state)
		{
			__state = EmeraldContribution.Blend(EmeraldRegistry.Get(setOne), EmeraldRegistry.Get(setTwo), lerp);
		}

		internal static void Postfix(ref WeatherSet blendedSet, EmeraldContribution __state)
		{
			EmeraldRegistry.Set(blendedSet, __state);
		}
	}
	[HarmonyPatch(typeof(WeatherSet), "CopyFrom")]
	internal static class CopyPatch
	{
		internal static void Prefix(WeatherSet originSet, out EmeraldContribution __state)
		{
			__state = EmeraldRegistry.Get(originSet);
		}

		internal static void Postfix(ref WeatherSet targetSet, EmeraldContribution __state)
		{
			EmeraldRegistry.Set(targetSet, __state);
		}
	}
	[HarmonyPatch(typeof(Weather), "ApplyWeather")]
	internal static class WeatherPatch
	{
		internal static void Prefix(ref OceanColorPalette ___finalPalette, WeatherSet ___previousWeatherSet, WeatherSet ___targetWeatherSet, float ___lerp)
		{
			Plugin instance = Plugin.Instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)Sun.sun == (Object)null))
			{
				instance.ApplyPalette(ref ___finalPalette, EmeraldContribution.Blend(EmeraldRegistry.Get(___previousWeatherSet), EmeraldRegistry.Get(___targetWeatherSet), ___lerp), Sun.sun.GetDawnLerp(), Sun.sun.GetNightLerp());
			}
		}
	}
	[HarmonyPatch(typeof(OceanColorBlender), "ApplyPalette")]
	internal static class MaterialPatch
	{
		internal static void Postfix(Material ___crestMaterial)
		{
			Plugin.Instance?.ApplyMaterial(___crestMaterial);
		}
	}
	internal struct OwnedValue<T> where T : struct
	{
		private bool applied;

		private T original;

		private T last;

		internal T Baseline(T current)
		{
			if (!applied || !EqualityComparer<T>.Default.Equals(current, last))
			{
				return current;
			}
			return original;
		}

		internal bool Update(T current, bool active, T configured, out T next)
		{
			bool flag = applied && EqualityComparer<T>.Default.Equals(current, last);
			next = current;
			if (active)
			{
				if (!flag)
				{
					original = current;
				}
				next = configured;
				last = next;
				applied = true;
			}
			else
			{
				if (flag)
				{
					next = original;
				}
				applied = false;
			}
			return !EqualityComparer<T>.Default.Equals(current, next);
		}
	}
	internal sealed class ScopedMaterial
	{
		private static readonly int ShallowId = Shader.PropertyToID("_SubSurfaceShallowCol");

		private static readonly int ScatteringId = Shader.PropertyToID("_SubSurfaceBase");

		private static readonly int SunId = Shader.PropertyToID("_SubSurfaceSun");

		private static readonly int TowardId = Shader.PropertyToID("_SkyTowardsSun");

		private static readonly int AwayId = Shader.PropertyToID("_SkyAwayFromSun");

		private Material current;

		private OwnedValue<Color> shallow;

		private OwnedValue<float> scattering;

		private OwnedValue<float> sun;

		private OwnedValue<Color> toward;

		private OwnedValue<Color> away;

		internal void Apply(Material material, float scope, SeaPreset preset)
		{
			if ((Object)(object)current != (Object)(object)material)
			{
				Restore();
				current = material;
			}
			ApplyCurrent(scope, preset);
		}

		internal void ApplyCurrent(float scope, SeaPreset preset)
		{
			if (!((Object)(object)current == (Object)null))
			{
				float weight = Mathf.Clamp01(scope);
				ApplyColor(ShallowId, ref shallow, preset?.Shallow, weight);
				ApplyColor(TowardId, ref toward, preset?.TowardSun, weight);
				ApplyColor(AwayId, ref away, preset?.AwayFromSun, weight);
				ApplyNumber(ScatteringId, ref scattering, preset?.BaseScattering, weight);
				ApplyNumber(SunId, ref sun, preset?.SunScattering, weight);
			}
		}

		private void ApplyColor(int id, ref OwnedValue<Color> state, Color? configured, float weight)
		{
			//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_0024: 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_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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			//IL_004a: 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_0071: Unknown result type (might be due to invalid IL or missing references)
			if (!current.HasProperty(id))
			{
				state = default(OwnedValue<Color>);
				return;
			}
			Color color = current.GetColor(id);
			Color val = state.Baseline(color);
			Color configured2 = Color.Lerp(val, configured ?? val, weight);
			configured2.a = val.a;
			if (state.Update(color, configured.HasValue && weight > 0f, configured2, out var next))
			{
				current.SetColor(id, next);
			}
		}

		private void ApplyNumber(int id, ref OwnedValue<float> state, float? configured, float weight)
		{
			if (!current.HasProperty(id))
			{
				state = default(OwnedValue<float>);
				return;
			}
			float num = current.GetFloat(id);
			float num2 = state.Baseline(num);
			float configured2 = Mathf.Lerp(num2, configured ?? num2, weight);
			if (state.Update(num, configured.HasValue && weight > 0f, configured2, out var next))
			{
				current.SetFloat(id, next);
			}
		}

		internal void Restore()
		{
			ApplyCurrent(0f, null);
			current = null;
			shallow = default(OwnedValue<Color>);
			scattering = default(OwnedValue<float>);
			sun = default(OwnedValue<float>);
			toward = default(OwnedValue<Color>);
			away = default(OwnedValue<Color>);
		}
	}
	internal sealed class SeaPreset
	{
		internal readonly Color Water;

		internal readonly Color Surface;

		internal readonly float Temperature;

		internal readonly float BaseScattering;

		internal readonly Color? Scattering;

		internal readonly Color? Fog;

		internal readonly Color? SkyTint;

		internal readonly Color? Shallow;

		internal readonly Color? TowardSun;

		internal readonly Color? AwayFromSun;

		internal readonly float? Tint;

		internal readonly float? Specular;

		internal readonly float? Atmosphere;

		internal readonly float? Exposure;

		internal readonly float? SunScattering;

		internal static readonly SeaPreset EmeraldSea;

		internal static readonly SeaPreset CaribbeanTurquoise;

		private SeaPreset(Color water, Color surface, float temperature, float baseScattering, Color? scattering = null, Color? fog = null, Color? skyTint = null, Color? shallow = null, Color? towardSun = null, Color? awayFromSun = null, float? tint = null, float? specular = null, float? atmosphere = null, float? exposure = null, float? sunScattering = null)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//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)
			Water = water;
			Surface = surface;
			Temperature = temperature;
			BaseScattering = baseScattering;
			Scattering = scattering;
			Fog = fog;
			SkyTint = skyTint;
			Shallow = shallow;
			TowardSun = towardSun;
			AwayFromSun = awayFromSun;
			Tint = tint;
			Specular = specular;
			Atmosphere = atmosphere;
			Exposure = exposure;
			SunScattering = sunScattering;
		}

		private static Color Rgb(int r, int g, int b)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			return new Color((float)r / 255f, (float)g / 255f, (float)b / 255f, 1f);
		}

		static SeaPreset()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_005b: 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_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_0133: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			Color water = Rgb(11, 143, 145);
			Color surface = Rgb(26, 127, 119);
			Color? scattering = Rgb(2, 113, 113);
			Color? towardSun = Rgb(171, 213, 239);
			Color? awayFromSun = Rgb(74, 126, 140);
			float? specular = 0.4f;
			float? atmosphere = 0.8f;
			float? exposure = 1.6f;
			float? sunScattering = 0f;
			EmeraldSea = new SeaPreset(water, surface, 15f, 0.4f, scattering, null, null, null, towardSun, awayFromSun, null, specular, atmosphere, exposure, sunScattering);
			Color water2 = Rgb(0, 184, 200);
			Color surface2 = Rgb(0, 184, 168);
			Color? scattering2 = Rgb(0, 136, 159);
			Color? fog = Rgb(181, 220, 224);
			Color? skyTint = Rgb(106, 168, 184);
			awayFromSun = Rgb(199, 220, 226);
			towardSun = Rgb(96, 127, 145);
			sunScattering = 0f;
			exposure = 0.4f;
			atmosphere = 0.8f;
			specular = 1.6f;
			float? sunScattering2 = 0f;
			CaribbeanTurquoise = new SeaPreset(water2, surface2, 5f, 0.4f, scattering2, fog, skyTint, null, awayFromSun, towardSun, sunScattering, exposure, atmosphere, specular, sunScattering2);
		}
	}
}