Decompiled source of AlternativeOceanColor v1.2.0

BepInEx/plugins/AlternativeOceanColor/AlternativeOceanColor.dll

Decompiled 3 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("AlternativeOceanColor")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]
[assembly: AssemblyProduct("AlternativeOceanColor")]
[assembly: AssemblyTitle("AlternativeOceanColor")]
[assembly: AssemblyVersion("1.2.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
{
	public enum OceanRegion
	{
		Aestrin = 1,
		Chronos,
		Both
	}
	internal sealed class SettingOrder
	{
		public int Order;
	}
	[BepInPlugin("DogEggz.AlternativeEmeraldSea", "Alternative Ocean Color", "1.2.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "DogEggz.AlternativeEmeraldSea";

		public const string Name = "Alternative Ocean Color";

		public const string Version = "1.2.0";

		private ConfigEntry<bool> presetEnabled;

		private ConfigEntry<bool> caribbeanTurquoise;

		private ConfigEntry<bool> emeraldSea;

		private ConfigEntry<bool> winterAestrin;

		private ConfigEntry<bool> openChronosOcean;

		private ConfigEntry<OceanRegion> winterRegion;

		private ConfigEntry<OceanRegion> chronosRegion;

		private bool changingSelection;

		private Harmony harmony;

		private readonly ScopedMaterial material = new ScopedMaterial();

		private RegionalContribution contribution;

		private float dayWeight;

		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;
			}
		}

		private SeaPreset AestrinPreset => PresetFor(OceanRegion.Aestrin);

		private SeaPreset ChronosPreset => PresetFor(OceanRegion.Chronos);

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

		private SeaPreset PresetFor(OceanRegion region)
		{
			if (winterAestrin.Value && Includes(winterRegion.Value, region))
			{
				return SeaPreset.WinterAestrin;
			}
			if (openChronosOcean.Value && Includes(chronosRegion.Value, region))
			{
				return SeaPreset.OpenChronosOcean;
			}
			return null;
		}

		private static bool Includes(OceanRegion selection, OceanRegion region)
		{
			return (selection & region) != 0;
		}

		private void Awake()
		{
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Expected O, but got Unknown
			Instance = this;
			presetEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Apply selected regional clear-day and saved clear dawn/dusk palettes. Cloudy/rain/storm and night retain their original contributions. Disable Ocean Color Configurator overrides when using this mod.");
			bool saveOnConfigSet = ((BaseUnityPlugin)this).Config.SaveOnConfigSet;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			caribbeanTurquoise = BindEmerald("Caribbean Turquoise", fallback: 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 = BindEmerald("Emerald Sea", fallback: 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.");
			winterAestrin = ((BaseUnityPlugin)this).Config.Bind<bool>("Aestrin", "Winter Aestrin", false, Description("Enable Winter Aestrin in the region(s) selected below. Temperature -10, clear-day specular 0.35.", 4));
			winterRegion = ((BaseUnityPlugin)this).Config.Bind<OceanRegion>("Aestrin", "Winter Aestrin - Apply to", OceanRegion.Aestrin, Description("Choose Aestrin, Chronos, or Both. The most recently enabled or reassigned preset takes overlapping regions; the other keeps any remaining region or turns off.", 3));
			openChronosOcean = ((BaseUnityPlugin)this).Config.Bind<bool>("Aestrin", "Open Chronos Ocean", true, Description("Enable the saved deep blue clear-day and clear dawn/dusk palette in the region(s) selected below.", 2));
			chronosRegion = ((BaseUnityPlugin)this).Config.Bind<OceanRegion>("Aestrin", "Open Chronos Ocean - Apply to", OceanRegion.Chronos, Description("Choose Aestrin, Chronos, or Both. The most recently enabled or reassigned preset takes overlapping regions; the other keeps any remaining region or turns off.", 1));
			if (!Enum.IsDefined(typeof(OceanRegion), winterRegion.Value))
			{
				winterRegion.Value = OceanRegion.Aestrin;
			}
			if (!Enum.IsDefined(typeof(OceanRegion), chronosRegion.Value))
			{
				chronosRegion.Value = OceanRegion.Chronos;
			}
			ResolveOverlap(openChronosOcean, chronosRegion, winterAestrin, winterRegion);
			if (caribbeanTurquoise.Value && emeraldSea.Value)
			{
				emeraldSea.Value = false;
			}
			presetEnabled.SettingChanged += SettingsChanged;
			caribbeanTurquoise.SettingChanged += SettingsChanged;
			emeraldSea.SettingChanged += SettingsChanged;
			winterAestrin.SettingChanged += SettingsChanged;
			openChronosOcean.SettingChanged += SettingsChanged;
			winterRegion.SettingChanged += SettingsChanged;
			chronosRegion.SettingChanged += SettingsChanged;
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = saveOnConfigSet;
			((BaseUnityPlugin)this).Config.Save();
			PaletteRegistry.Clear();
			harmony = new Harmony("DogEggz.AlternativeEmeraldSea");
			harmony.PatchAll(Assembly.GetExecutingAssembly());
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Alternative Ocean Color 1.2.0 loaded: Emerald, Aestrin, and Chronos regional presets.");
		}

		private static ConfigDescription Description(string text, int order)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			return new ConfigDescription(text, (AcceptableValueBase)null, new object[1]
			{
				new SettingOrder
				{
					Order = order
				}
			});
		}

		private ConfigEntry<bool> BindEmerald(string key, bool fallback, string description)
		{
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Presets", key, fallback, (ConfigDescription)null);
			ConfigEntry<bool> result = ((BaseUnityPlugin)this).Config.Bind<bool>("Emerald Archipelagos", key, val.Value, description);
			((BaseUnityPlugin)this).Config.Remove(((ConfigEntryBase)val).Definition);
			return result;
		}

		private static void ResolveOverlap(ConfigEntry<bool> winner, ConfigEntry<OceanRegion> winnerRegion, ConfigEntry<bool> other, ConfigEntry<OceanRegion> otherRegion)
		{
			if (winner.Value && other.Value && Includes(winnerRegion.Value, otherRegion.Value))
			{
				OceanRegion oceanRegion = otherRegion.Value & ~winnerRegion.Value;
				if (oceanRegion == (OceanRegion)0)
				{
					other.Value = false;
				}
				else
				{
					otherRegion.Value = oceanRegion;
				}
			}
		}

		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;
				}
				if (sender == winterAestrin || sender == winterRegion)
				{
					ResolveOverlap(winterAestrin, winterRegion, openChronosOcean, chronosRegion);
				}
				else if (sender == openChronosOcean || sender == chronosRegion)
				{
					ResolveOverlap(openChronosOcean, chronosRegion, winterAestrin, winterRegion);
				}
				material.ApplyCurrent(GetMaterialOverrides());
			}
			finally
			{
				changingSelection = false;
			}
		}

		internal void ApplyPalette(ref OceanColorPalette palette, RegionalContribution source, float dawn, float night)
		{
			contribution = source;
			float num = 1f - Mathf.Clamp01(night);
			float dawn2 = Mathf.Clamp01(dawn) * num;
			dayWeight = (1f - Mathf.Clamp01(dawn)) * num;
			if (Active)
			{
				source.Emerald.Apply(ref palette, SelectedPreset, dayWeight, dawn2);
				source.Aestrin.Apply(ref palette, AestrinPreset, dayWeight, dawn2);
				source.Chronos.Apply(ref palette, ChronosPreset, dayWeight, dawn2);
			}
		}

		private MaterialOverrides GetMaterialOverrides()
		{
			MaterialOverrides result = default(MaterialOverrides);
			if (!Active)
			{
				return result;
			}
			result.Add(SelectedPreset, contribution.Emerald.Weight * dayWeight);
			result.Add(AestrinPreset, contribution.Aestrin.Weight * dayWeight);
			result.Add(ChronosPreset, contribution.Chronos.Weight * dayWeight);
			return result;
		}

		internal void ApplyMaterial(Material ocean)
		{
			material.Apply(ocean, GetMaterialOverrides());
		}

		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;
			}
			if (winterAestrin != null)
			{
				winterAestrin.SettingChanged -= SettingsChanged;
			}
			if (openChronosOcean != null)
			{
				openChronosOcean.SettingChanged -= SettingsChanged;
			}
			if (winterRegion != null)
			{
				winterRegion.SettingChanged -= SettingsChanged;
			}
			if (chronosRegion != null)
			{
				chronosRegion.SettingChanged -= SettingsChanged;
			}
			material.Restore();
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			PaletteRegistry.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 RegionalContribution __state)
		{
			__state = RegionalContribution.Blend(PaletteRegistry.Get(setOne), PaletteRegistry.Get(setTwo), lerp);
		}

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

		internal static void Postfix(ref WeatherSet targetSet, RegionalContribution __state)
		{
			PaletteRegistry.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, RegionalContribution.Blend(PaletteRegistry.Get(___previousWeatherSet), PaletteRegistry.Get(___targetWeatherSet), ___lerp), Sun.sun.GetDawnLerp(), Sun.sun.GetNightLerp());
			}
		}
	}
	[HarmonyPatch(typeof(RegionBlender), "Start")]
	internal static class RegionStartPatch
	{
		internal static void Prefix(RegionBlender __instance, out Region __state)
		{
			__state = PaletteRegistry.SourceRegion;
			PaletteRegistry.SourceRegion = __instance.initialRegion;
		}

		internal static void Finalizer(Region __state)
		{
			PaletteRegistry.SourceRegion = __state;
		}
	}
	[HarmonyPatch(typeof(RegionBlender), "UpdateBlend")]
	internal static class RegionBlendPatch
	{
		internal static void Prefix(Region ___currentTargetRegion, out Region __state)
		{
			__state = PaletteRegistry.SourceRegion;
			PaletteRegistry.SourceRegion = ___currentTargetRegion;
		}

		internal static void Finalizer(Region __state)
		{
			PaletteRegistry.SourceRegion = __state;
		}
	}
	[HarmonyPatch(typeof(OceanColorBlender), "ApplyPalette")]
	internal static class MaterialPatch
	{
		internal static void Postfix(Material ___crestMaterial)
		{
			Plugin.Instance?.ApplyMaterial(___crestMaterial);
		}
	}
	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 readonly Color? DawnWater;

		internal readonly Color? DawnSurface;

		internal readonly Color? DawnScattering;

		internal static readonly SeaPreset EmeraldSea;

		internal static readonly SeaPreset CaribbeanTurquoise;

		internal static readonly SeaPreset WinterAestrin;

		internal static readonly SeaPreset OpenChronosOcean;

		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, Color? dawnWater = null, Color? dawnSurface = null, Color? dawnScattering = 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;
			DawnWater = dawnWater;
			DawnSurface = dawnSurface;
			DawnScattering = dawnScattering;
		}

		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_0043: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: 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)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: 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_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_039d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: 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? shallow = Rgb(50, 159, 141);
			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;
			Color? dawnWater = Rgb(40, 111, 112);
			Color? dawnSurface = Rgb(100, 138, 130);
			Color? dawnScattering = Rgb(52, 123, 115);
			EmeraldSea = new SeaPreset(water, surface, 15f, 0.4f, scattering, null, null, shallow, towardSun, awayFromSun, null, specular, atmosphere, exposure, sunScattering, dawnWater, dawnSurface, dawnScattering);
			CaribbeanTurquoise = new SeaPreset(Rgb(0, 184, 200), Rgb(0, 184, 168), 5f, 0.4f, Rgb(0, 136, 159), Rgb(181, 220, 224), Rgb(106, 168, 184), Rgb(66, 190, 198), Rgb(199, 220, 226), Rgb(96, 127, 145), 0f, 0.4f, 0.8f, 1.6f, 0f, Rgb(40, 126, 136), Rgb(107, 151, 153), Rgb(63, 145, 149));
			Color water2 = Rgb(36, 85, 138);
			Color surface2 = Rgb(66, 108, 149);
			Color? scattering2 = Rgb(52, 114, 166);
			dawnScattering = Rgb(79, 135, 184);
			dawnSurface = Rgb(187, 205, 229);
			dawnWater = Rgb(69, 94, 136);
			sunScattering = 0f;
			exposure = 0.35f;
			WinterAestrin = new SeaPreset(water2, surface2, -10f, 0.35f, scattering2, null, null, dawnScattering, dawnSurface, dawnWater, sunScattering, exposure);
			Color water3 = Rgb(16, 51, 104);
			Color surface3 = Rgb(36, 74, 118);
			Color? scattering3 = Rgb(27, 83, 141);
			dawnWater = Rgb(53, 111, 163);
			dawnSurface = Rgb(169, 190, 216);
			dawnScattering = Rgb(52, 79, 115);
			exposure = 0f;
			sunScattering = 0.4f;
			awayFromSun = Rgb(39, 74, 118);
			towardSun = Rgb(83, 106, 137);
			shallow = Rgb(54, 95, 141);
			OpenChronosOcean = new SeaPreset(water3, surface3, 0f, 0.25f, scattering3, null, null, dawnWater, dawnSurface, dawnScattering, exposure, sunScattering, null, null, null, awayFromSun, towardSun, shallow);
		}
	}
	internal struct PaletteContribution
	{
		internal float Weight;

		internal Color Water;

		internal Color Surface;

		internal Color Scattering;

		internal Color DawnWater;

		internal Color DawnSurface;

		internal Color DawnScattering;

		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 PaletteContribution From(WeatherSet source)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: 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_000d: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_003f: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_005e: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00a7: 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_00d4: Unknown result type (might be due to invalid IL or missing references)
			OceanColorPalette dayPalette = source.dayPalette;
			OceanColorPalette dawnPalette = source.dawnPalette;
			PaletteContribution result = new PaletteContribution
			{
				Weight = 1f,
				Water = dayPalette.waterColor,
				Surface = dayPalette.surfaceColor,
				Scattering = dayPalette.scatteringColor,
				Temperature = dayPalette.temperature,
				DawnWater = dawnPalette.waterColor,
				DawnSurface = dawnPalette.surfaceColor,
				DawnScattering = dawnPalette.scatteringColor,
				Fog = dayPalette.fog,
				Tint = dayPalette.tint,
				Specular = dayPalette.oceanSpecular
			};
			Material skyMaterial = dayPalette.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 PaletteContribution Blend(PaletteContribution one, PaletteContribution 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_009e: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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)
			//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_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Clamp01(lerp);
			float num2 = 1f - num;
			return new PaletteContribution
			{
				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,
				DawnWater = one.DawnWater * num2 + two.DawnWater * num,
				DawnSurface = one.DawnSurface * num2 + two.DawnSurface * num,
				DawnScattering = one.DawnScattering * num2 + two.DawnScattering * 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 Apply(ref OceanColorPalette palette, SeaPreset preset, float day, float dawn)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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_0030: 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_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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: 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_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			if (preset != null && !(Weight <= 0f))
			{
				palette.waterColor = ReplaceRgb(palette.waterColor, Water, preset.Water, Weight, day);
				palette.surfaceColor = ReplaceRgb(palette.surfaceColor, Surface, preset.Surface, Weight, day);
				if (preset.Scattering.HasValue)
				{
					palette.scatteringColor = ReplaceRgb(palette.scatteringColor, Scattering, preset.Scattering.Value, Weight, day);
				}
				if (preset.Fog.HasValue)
				{
					palette.fog = ReplaceRgb(palette.fog, Fog, preset.Fog.Value, Weight, day);
				}
				palette.temperature += (preset.Temperature * Weight - Temperature) * day;
				if (preset.Tint.HasValue)
				{
					palette.tint += (preset.Tint.Value * Weight - Tint) * day;
				}
				if (preset.Specular.HasValue)
				{
					palette.oceanSpecular += (preset.Specular.Value * Weight - Specular) * day;
				}
				if (preset.DawnWater.HasValue)
				{
					palette.waterColor = ReplaceRgb(palette.waterColor, DawnWater, preset.DawnWater.Value, Weight, dawn);
				}
				if (preset.DawnSurface.HasValue)
				{
					palette.surfaceColor = ReplaceRgb(palette.surfaceColor, DawnSurface, preset.DawnSurface.Value, Weight, dawn);
				}
				if (preset.DawnScattering.HasValue)
				{
					palette.scatteringColor = ReplaceRgb(palette.scatteringColor, DawnScattering, preset.DawnScattering.Value, Weight, dawn);
				}
				ApplySky(palette.skyMaterial, preset, day);
			}
		}

		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 struct RegionalContribution
	{
		internal PaletteContribution Emerald;

		internal PaletteContribution Aestrin;

		internal PaletteContribution Chronos;

		internal static RegionalContribution Blend(RegionalContribution one, RegionalContribution two, float t)
		{
			return new RegionalContribution
			{
				Emerald = PaletteContribution.Blend(one.Emerald, two.Emerald, t),
				Aestrin = PaletteContribution.Blend(one.Aestrin, two.Aestrin, t),
				Chronos = PaletteContribution.Blend(one.Chronos, two.Chronos, t)
			};
		}
	}
	internal static class PaletteRegistry
	{
		private sealed class Entry
		{
			internal RegionalContribution Value;
		}

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

		internal static Region SourceRegion;

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

		internal static RegionalContribution Get(WeatherSet set)
		{
			if ((Object)(object)set == (Object)null)
			{
				return default(RegionalContribution);
			}
			if ((Object)(object)SourceRegion != (Object)null && (Object)(object)set == (Object)(object)SourceRegion.clearWeather)
			{
				RegionalContribution result = default(RegionalContribution);
				if (Named(((Object)SourceRegion).name, "Region Medi East"))
				{
					result.Chronos = PaletteContribution.From(set);
				}
				else if (Named(((Object)SourceRegion).name, "Region Medi"))
				{
					result.Aestrin = PaletteContribution.From(set);
				}
				else if (Named(((Object)set).name, "W emerald Clear"))
				{
					result.Emerald = PaletteContribution.From(set);
				}
				return result;
			}
			if (entries.TryGetValue(set, out var value))
			{
				return value.Value;
			}
			if (!Named(((Object)set).name, "W emerald Clear"))
			{
				return default(RegionalContribution);
			}
			return new RegionalContribution
			{
				Emerald = PaletteContribution.From(set)
			};
		}

		private static bool Named(string actual, string expected)
		{
			if (!string.Equals(actual, expected, StringComparison.OrdinalIgnoreCase))
			{
				return string.Equals(actual, expected + "(Clone)", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		internal static void Set(WeatherSet set, RegionalContribution 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
				});
			}
		}
	}
	internal struct WeightedColor
	{
		internal Color Sum;

		internal float Weight;

		internal void Add(Color? color, float weight)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			if (color.HasValue)
			{
				Sum += color.Value * weight;
				Weight += weight;
			}
		}
	}
	internal struct WeightedNumber
	{
		internal float Sum;

		internal float Weight;

		internal void Add(float? number, float weight)
		{
			if (number.HasValue)
			{
				Sum += number.Value * weight;
				Weight += weight;
			}
		}
	}
	internal struct MaterialOverrides
	{
		internal WeightedColor Shallow;

		internal WeightedColor Toward;

		internal WeightedColor Away;

		internal WeightedNumber Scattering;

		internal WeightedNumber Sun;

		internal void Add(SeaPreset preset, float weight)
		{
			if (preset != null && !(weight <= 0f))
			{
				Shallow.Add(preset.Shallow, weight);
				Toward.Add(preset.TowardSun, weight);
				Away.Add(preset.AwayFromSun, weight);
				Scattering.Add(preset.BaseScattering, weight);
				Sun.Add(preset.SunScattering, weight);
			}
		}
	}
	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, MaterialOverrides values)
		{
			if ((Object)(object)current != (Object)(object)material)
			{
				Restore();
				current = material;
			}
			ApplyCurrent(values);
		}

		internal void ApplyCurrent(MaterialOverrides values)
		{
			if (!((Object)(object)current == (Object)null))
			{
				ApplyColor(ShallowId, ref shallow, values.Shallow);
				ApplyColor(TowardId, ref toward, values.Toward);
				ApplyColor(AwayId, ref away, values.Away);
				ApplyNumber(ScatteringId, ref scattering, values.Scattering);
				ApplyNumber(SunId, ref sun, values.Sun);
			}
		}

		private void ApplyColor(int id, ref OwnedValue<Color> state, WeightedColor configured)
		{
			//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_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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_005c: 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_007b: 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 = val * (1f - Mathf.Clamp01(configured.Weight)) + configured.Sum;
			configured2.a = val.a;
			if (state.Update(color, configured.Weight > 0f, configured2, out var next))
			{
				current.SetColor(id, next);
			}
		}

		private void ApplyNumber(int id, ref OwnedValue<float> state, WeightedNumber configured)
		{
			if (!current.HasProperty(id))
			{
				state = default(OwnedValue<float>);
				return;
			}
			float num = current.GetFloat(id);
			float configured2 = state.Baseline(num) * (1f - Mathf.Clamp01(configured.Weight)) + configured.Sum;
			if (state.Update(num, configured.Weight > 0f, configured2, out var next))
			{
				current.SetFloat(id, next);
			}
		}

		internal void Restore()
		{
			ApplyCurrent(default(MaterialOverrides));
			current = null;
			shallow = default(OwnedValue<Color>);
			scattering = default(OwnedValue<float>);
			sun = default(OwnedValue<float>);
			toward = default(OwnedValue<Color>);
			away = default(OwnedValue<Color>);
		}
	}
}