Decompiled source of GammaOfNightLights v1.0.10

GammaOfNightLights.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using ConditionalConfigSync;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Gamma of Night Lights")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Gamma of Night Lights")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b50cb9cc-89c7-4636-90be-6d6ae9417719")]
[assembly: AssemblyFileVersion("1.0.10")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.10.0")]
[module: UnverifiableCode]
public struct HSLColor
{
	public float h;

	public float s;

	public float l;

	public float a;

	public HSLColor(float h, float s, float l, float a)
	{
		this.h = h;
		this.s = s;
		this.l = l;
		this.a = a;
	}

	public HSLColor(float h, float s, float l)
	{
		this.h = h;
		this.s = s;
		this.l = l;
		a = 1f;
	}

	public HSLColor(Color c)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		HSLColor hSLColor = FromRGBA(c);
		h = hSLColor.h;
		s = hSLColor.s;
		l = hSLColor.l;
		a = hSLColor.a;
	}

	public static HSLColor FromRGBA(Color c)
	{
		//IL_0001: 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_0019: 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_002c: 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_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_00df: 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_010a: Unknown result type (might be due to invalid IL or missing references)
		float num = c.a;
		float num2 = Mathf.Min(Mathf.Min(c.r, c.g), c.b);
		float num3 = Mathf.Max(Mathf.Max(c.r, c.g), c.b);
		float num4 = (num2 + num3) / 2f;
		float num5;
		float num6;
		if (num2 == num3)
		{
			num5 = 0f;
			num6 = 0f;
		}
		else
		{
			float num7 = num3 - num2;
			num5 = ((num4 <= 0.5f) ? (num7 / (num3 + num2)) : (num7 / (2f - (num3 + num2))));
			num6 = 0f;
			if (c.r == num3)
			{
				num6 = (c.g - c.b) / num7;
			}
			else if (c.g == num3)
			{
				num6 = 2f + (c.b - c.r) / num7;
			}
			else if (c.b == num3)
			{
				num6 = 4f + (c.r - c.g) / num7;
			}
			num6 = Mathf.Repeat(num6 * 60f, 360f);
		}
		return new HSLColor(num6, num5, num4, num);
	}

	public Color ToRGBA()
	{
		//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)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		float num = a;
		float num2 = ((l <= 0.5f) ? (l * (1f + s)) : (l + s - l * s));
		float n = 2f * l - num2;
		float num3;
		float num4;
		float num5;
		if (s == 0f)
		{
			num3 = (num4 = (num5 = l));
		}
		else
		{
			num3 = Value(n, num2, h + 120f);
			num4 = Value(n, num2, h);
			num5 = Value(n, num2, h - 120f);
		}
		return new Color(num3, num4, num5, num);
	}

	private static float Value(float n1, float n2, float hue)
	{
		hue = Mathf.Repeat(hue, 360f);
		if (hue < 60f)
		{
			return n1 + (n2 - n1) * hue / 60f;
		}
		if (hue < 180f)
		{
			return n2;
		}
		if (hue < 240f)
		{
			return n1 + (n2 - n1) * (240f - hue) / 60f;
		}
		return n1;
	}

	public static implicit operator HSLColor(Color src)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		return FromRGBA(src);
	}

	public static implicit operator Color(HSLColor src)
	{
		//IL_0003: 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_000b: Unknown result type (might be due to invalid IL or missing references)
		return src.ToRGBA();
	}
}
namespace GammaOfNightLights;

[BepInPlugin("shudnal.GammaOfNightLights", "Gamma of Night Lights", "1.0.10")]
[BepInDependency("_shudnal.ConditionalConfigSync", "1.0.5")]
public class GammaOfNightLights : BaseUnityPlugin
{
	[HarmonyPatch(typeof(EnvMan), "SetEnv")]
	public static class EnvMan_SetEnv_LuminancePatch
	{
		private struct LightState
		{
			public Color m_ambColorNight;

			public Color m_fogColorNight;

			public Color m_fogColorSunNight;

			public Color m_sunColorNight;

			public Color m_fogColorMorning;

			public Color m_fogColorSunMorning;

			public Color m_sunColorMorning;

			public Color m_ambColorDay;

			public Color m_fogColorDay;

			public Color m_fogColorSunDay;

			public Color m_sunColorDay;

			public Color m_sunColorEvening;

			public Color m_fogColorEvening;

			public Color m_fogColorSunEvening;

			public float m_lightIntensityDay;

			public float m_lightIntensityNight;

			public float m_fogDensityNight;

			public float m_fogDensityMorning;

			public float m_fogDensityDay;

			public float m_fogDensityEvening;
		}

		private static LightState _lightState;

		private static Color ChangeColorLuminance(Color color, float luminanceMultiplier)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_000e: 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)
			if (luminanceMultiplier == 1f)
			{
				return color;
			}
			HSLColor hSLColor = new HSLColor(color);
			hSLColor.l *= luminanceMultiplier;
			return hSLColor.ToRGBA();
		}

		private static void SaveState(EnvSetup env)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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)
			_lightState.m_ambColorNight = env.m_ambColorNight;
			_lightState.m_sunColorNight = env.m_sunColorNight;
			_lightState.m_fogColorNight = env.m_fogColorNight;
			_lightState.m_fogColorSunNight = env.m_fogColorSunNight;
			_lightState.m_ambColorDay = env.m_ambColorDay;
			_lightState.m_sunColorDay = env.m_sunColorDay;
			_lightState.m_fogColorDay = env.m_fogColorDay;
			_lightState.m_fogColorSunDay = env.m_fogColorSunDay;
			_lightState.m_sunColorMorning = env.m_sunColorMorning;
			_lightState.m_fogColorMorning = env.m_fogColorMorning;
			_lightState.m_fogColorSunMorning = env.m_fogColorSunMorning;
			_lightState.m_sunColorEvening = env.m_sunColorEvening;
			_lightState.m_fogColorEvening = env.m_fogColorEvening;
			_lightState.m_fogColorSunEvening = env.m_fogColorSunEvening;
			_lightState.m_lightIntensityDay = env.m_lightIntensityDay;
			_lightState.m_lightIntensityNight = env.m_lightIntensityNight;
			_lightState.m_fogDensityNight = env.m_fogDensityNight;
			_lightState.m_fogDensityMorning = env.m_fogDensityMorning;
			_lightState.m_fogDensityDay = env.m_fogDensityDay;
			_lightState.m_fogDensityEvening = env.m_fogDensityEvening;
		}

		private static void RestoreState(EnvSetup env)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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)
			env.m_ambColorNight = _lightState.m_ambColorNight;
			env.m_sunColorNight = _lightState.m_sunColorNight;
			env.m_fogColorNight = _lightState.m_fogColorNight;
			env.m_fogColorSunNight = _lightState.m_fogColorSunNight;
			env.m_ambColorDay = _lightState.m_ambColorDay;
			env.m_sunColorDay = _lightState.m_sunColorDay;
			env.m_fogColorDay = _lightState.m_fogColorDay;
			env.m_fogColorSunDay = _lightState.m_fogColorSunDay;
			env.m_sunColorMorning = _lightState.m_sunColorMorning;
			env.m_fogColorMorning = _lightState.m_fogColorMorning;
			env.m_fogColorSunMorning = _lightState.m_fogColorSunMorning;
			env.m_sunColorEvening = _lightState.m_sunColorEvening;
			env.m_fogColorEvening = _lightState.m_fogColorEvening;
			env.m_fogColorSunEvening = _lightState.m_fogColorSunEvening;
			env.m_fogDensityNight = _lightState.m_fogDensityNight;
			env.m_fogDensityMorning = _lightState.m_fogDensityMorning;
			env.m_fogDensityDay = _lightState.m_fogDensityDay;
			env.m_fogDensityEvening = _lightState.m_fogDensityEvening;
			env.m_lightIntensityDay = _lightState.m_lightIntensityDay;
			env.m_lightIntensityNight = _lightState.m_lightIntensityNight;
		}

		private static bool TryGetMultipliers(bool indoors, out float nightLum, out float morningLum, out float dayLum, out float eveningLum, out float fogNight, out float fogMorning, out float fogDay, out float fogEvening, out float sunMul, out float moonMul)
		{
			sunMul = lightIntensityDayMultiplier.Value;
			moonMul = lightIntensityNightMultiplier.Value;
			if (indoors)
			{
				nightLum = (morningLum = (dayLum = (eveningLum = indoorLuminanceMultiplier.Value)));
				fogNight = (fogMorning = (fogDay = (fogEvening = fogDensityIndoorsMultiplier.Value)));
			}
			else
			{
				nightLum = nightLuminanceMultiplier.Value;
				morningLum = morningLuminanceMultiplier.Value;
				dayLum = dayLuminanceMultiplier.Value;
				eveningLum = eveningLuminanceMultiplier.Value;
				fogNight = fogDensityNightMultiplier.Value;
				fogMorning = fogDensityMorningMultiplier.Value;
				fogDay = fogDensityDayMultiplier.Value;
				fogEvening = fogDensityEveningMultiplier.Value;
			}
			return nightLum != 1f || morningLum != 1f || dayLum != 1f || eveningLum != 1f || fogNight != 1f || fogMorning != 1f || fogDay != 1f || fogEvening != 1f || sunMul != 1f || moonMul != 1f;
		}

		private static void ApplyMultipliers(EnvSetup env, float nightLum, float morningLum, float dayLum, float eveningLum, float fogNight, float fogMorning, float fogDay, float fogEvening, float sunMul, float moonMul)
		{
			//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_0025: 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_0042: 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_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_006c: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			if (nightLum != 1f)
			{
				env.m_ambColorNight = ChangeColorLuminance(env.m_ambColorNight, nightLum);
				env.m_fogColorNight = ChangeColorLuminance(env.m_fogColorNight, nightLum);
				env.m_fogColorSunNight = ChangeColorLuminance(env.m_fogColorSunNight, nightLum);
				env.m_sunColorNight = ChangeColorLuminance(env.m_sunColorNight, nightLum);
			}
			if (morningLum != 1f)
			{
				env.m_fogColorMorning = ChangeColorLuminance(env.m_fogColorMorning, morningLum);
				env.m_fogColorSunMorning = ChangeColorLuminance(env.m_fogColorSunMorning, morningLum);
				env.m_sunColorMorning = ChangeColorLuminance(env.m_sunColorMorning, morningLum);
			}
			if (dayLum != 1f)
			{
				env.m_ambColorDay = ChangeColorLuminance(env.m_ambColorDay, dayLum);
				env.m_fogColorDay = ChangeColorLuminance(env.m_fogColorDay, dayLum);
				env.m_fogColorSunDay = ChangeColorLuminance(env.m_fogColorSunDay, dayLum);
				env.m_sunColorDay = ChangeColorLuminance(env.m_sunColorDay, dayLum);
			}
			if (eveningLum != 1f)
			{
				env.m_fogColorEvening = ChangeColorLuminance(env.m_fogColorEvening, eveningLum);
				env.m_fogColorSunEvening = ChangeColorLuminance(env.m_fogColorSunEvening, eveningLum);
				env.m_sunColorEvening = ChangeColorLuminance(env.m_sunColorEvening, eveningLum);
			}
			if (fogNight != 1f)
			{
				env.m_fogDensityNight *= fogNight;
			}
			if (fogMorning != 1f)
			{
				env.m_fogDensityMorning *= fogMorning;
			}
			if (fogDay != 1f)
			{
				env.m_fogDensityDay *= fogDay;
			}
			if (fogEvening != 1f)
			{
				env.m_fogDensityEvening *= fogEvening;
			}
			if (sunMul != 1f)
			{
				env.m_lightIntensityDay *= sunMul;
			}
			if (moonMul != 1f)
			{
				env.m_lightIntensityNight *= moonMul;
			}
		}

		[HarmonyPriority(0)]
		public static void Prefix(EnvSetup env, ref bool __state)
		{
			if (modEnabled.Value)
			{
				bool indoors = Object.op_Implicit((Object)(object)Player.m_localPlayer) && ((Character)Player.m_localPlayer).InInterior();
				__state = TryGetMultipliers(indoors, out var nightLum, out var morningLum, out var dayLum, out var eveningLum, out var fogNight, out var fogMorning, out var fogDay, out var fogEvening, out var sunMul, out var moonMul);
				if (__state)
				{
					SaveState(env);
					ApplyMultipliers(env, nightLum, morningLum, dayLum, eveningLum, fogNight, fogMorning, fogDay, fogEvening, sunMul, moonMul);
				}
			}
		}

		[HarmonyPriority(800)]
		public static void Postfix(EnvSetup env, bool __state)
		{
			if (__state)
			{
				RestoreState(env);
			}
		}
	}

	[HarmonyPatch(typeof(EnvMan), "RescaleDayFraction")]
	public static class EnvMan_RescaleDayFraction_DayNightLength
	{
		[HarmonyPriority(700)]
		public static bool Prefix(float fraction, ref float __result)
		{
			if (!ControlNightLength())
			{
				return true;
			}
			float dayStartFraction = GetDayStartFraction();
			float num = 1f - dayStartFraction;
			if (dayStartFraction <= fraction && fraction <= num)
			{
				float num2 = (fraction - dayStartFraction) / (num - dayStartFraction);
				fraction = 0.25f + num2 * 0.5f;
			}
			else if (fraction < 0.5f)
			{
				fraction = fraction / dayStartFraction * 0.25f;
			}
			else
			{
				float num3 = (fraction - num) / dayStartFraction;
				fraction = 0.75f + num3 * 0.25f;
			}
			__result = fraction;
			return false;
		}
	}

	[HarmonyPatch(typeof(EnvMan), "GetMorningStartSec")]
	public static class EnvMan_GetMorningStartSec_DayNightLength
	{
		[HarmonyPriority(700)]
		public static bool Prefix(EnvMan __instance, int day, ref double __result)
		{
			if (!ControlNightLength())
			{
				return true;
			}
			__result = (float)(day * __instance.m_dayLengthSec) + (float)__instance.m_dayLengthSec * GetDayStartFraction();
			return false;
		}
	}

	[HarmonyPatch(typeof(EnvMan), "SkipToMorning")]
	public static class EnvMan_SkipToMorning_DayNightLength
	{
		[HarmonyPriority(700)]
		public static bool Prefix(EnvMan __instance, ref bool ___m_skipTime, ref double ___m_skipToTime, ref double ___m_timeSkipSpeed)
		{
			if (!ControlNightLength())
			{
				return true;
			}
			if (GetDayStartFraction() == 0.15f)
			{
				return true;
			}
			double timeSeconds = ZNet.instance.GetTimeSeconds();
			double num = timeSeconds - timeSeconds % (double)__instance.m_dayLengthSec + (double)((float)__instance.m_dayLengthSec * GetDayStartFraction());
			int day = __instance.GetDay(num);
			double morningStartSec = __instance.GetMorningStartSec(day + 1);
			___m_skipTime = true;
			___m_skipToTime = morningStartSec;
			double num2 = morningStartSec - timeSeconds;
			___m_timeSkipSpeed = num2 / 12.0;
			LogInfo($"Time: {timeSeconds,-10:F2} Day: {day} Next morning: {morningStartSec,-10:F2} Skipspeed: {___m_timeSkipSpeed,-5:F2}");
			return false;
		}
	}

	[HarmonyPatch]
	public static class EnvMan_DayLength
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(EnvMan), "Awake", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(EnvMan), "FixedUpdate", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(EnvMan), "GetCurrentDay", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(EnvMan), "GetDay", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(EnvMan), "GetMorningStartSec", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(EnvMan), "SkipToMorning", (Type[])null, (Type[])null);
		}

		[HarmonyPriority(800)]
		private static void Prefix(ref long ___m_dayLengthSec)
		{
			if (enableDayNightCycle.Value && dayLengthSec.Value != 0L && ___m_dayLengthSec != dayLengthSec.Value)
			{
				___m_dayLengthSec = dayLengthSec.Value;
			}
		}
	}

	public const string pluginID = "shudnal.GammaOfNightLights";

	public const string pluginName = "Gamma of Night Lights";

	public const string pluginVersion = "1.0.10";

	private readonly Harmony harmony = new Harmony("shudnal.GammaOfNightLights");

	internal static readonly ConfigSync configSync = new ConfigSync("shudnal.GammaOfNightLights")
	{
		DisplayName = "Gamma of Night Lights",
		CurrentVersion = "1.0.10",
		MinimumRequiredVersion = "1.0.10"
	};

	private static ConfigEntry<bool> modEnabled;

	private static ConfigEntry<bool> configLocked;

	private static ConfigEntry<float> indoorLuminanceMultiplier;

	private static ConfigEntry<float> fogDensityIndoorsMultiplier;

	private static ConfigEntry<float> dayLuminanceMultiplier;

	private static ConfigEntry<float> fogDensityDayMultiplier;

	private static ConfigEntry<float> eveningLuminanceMultiplier;

	private static ConfigEntry<float> fogDensityEveningMultiplier;

	private static ConfigEntry<float> morningLuminanceMultiplier;

	private static ConfigEntry<float> fogDensityMorningMultiplier;

	private static ConfigEntry<float> nightLuminanceMultiplier;

	private static ConfigEntry<float> fogDensityNightMultiplier;

	private static ConfigEntry<float> lightIntensityDayMultiplier;

	private static ConfigEntry<float> lightIntensityNightMultiplier;

	private static ConfigEntry<bool> enableDayNightCycle;

	private static ConfigEntry<int> nightLength;

	private static ConfigEntry<long> dayLengthSec;

	public static GammaOfNightLights instance;

	private void Awake()
	{
		harmony.PatchAll();
		instance = this;
		Game.isModded = true;
		ConfigInit();
		((ConditionalConfigSync)configSync).AddLockingConfigEntry<bool>(configLocked);
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.Save();
		Harmony obj = harmony;
		if (obj != null)
		{
			obj.UnpatchSelf();
		}
	}

	public static void LogInfo(object data)
	{
		((BaseUnityPlugin)instance).Logger.LogInfo(data);
	}

	private void ConfigInit()
	{
		modEnabled = config("General", "Enabled", defaultValue: true, "Enable the mod");
		configLocked = config("General", "Lock Configuration", defaultValue: true, "Configuration is locked and can be changed by server admins only.");
		enableDayNightCycle = config("Day night cycle", "Enabled", defaultValue: false, "Enable changing the day/night cycle");
		nightLength = config("Day night cycle", "Night length", 30, "Night length in percents of all day length. Default is 30%. Left it at 30 to preserve compatibility with other mods.");
		dayLengthSec = config("Day night cycle", "Day length in seconds", 1800L, "Day length in seconds. Vanilla - 1800 seconds.");
		indoorLuminanceMultiplier = config("Location - Indoors", "Luminance at instanced locations", 1f, "Ambient light luminance multiplier to be applied indoors");
		fogDensityIndoorsMultiplier = config("Location - Indoors", "Fog density indoors", 1f, "Fog density multiplier indoors");
		nightLuminanceMultiplier = config("Time - Night", "Luminance at night", 1f, "Ambient light luminance multiplier to be applied at nighttime");
		fogDensityNightMultiplier = config("Time - Night", "Fog density at night", 1f, "Fog density multiplier at nighttime");
		dayLuminanceMultiplier = config("Time - Day", "Luminance at day", 1f, "Ambient light luminance multiplier to be applied at daytime");
		fogDensityDayMultiplier = config("Time - Day", "Fog density at day", 1f, "Fog density multiplier at daytime");
		eveningLuminanceMultiplier = config("Time - Evening", "Luminance at evening", 1f, "Ambient luminance multiplier to be applied at evening");
		fogDensityEveningMultiplier = config("Time - Evening", "Fog density at evening", 1f, "Fog density multiplier at evening");
		morningLuminanceMultiplier = config("Time - Morning", "Luminance at morning", 1f, "Ambient luminance multiplier to be applied at morning");
		fogDensityMorningMultiplier = config("Time - Morning", "Fog density at morning", 1f, "Fog density multiplier at morning");
		lightIntensityDayMultiplier = config("Light intensity", "Sunlight intensity", 1f, "Light intensity daytime multiplier (sun)");
		lightIntensityNightMultiplier = config("Light intensity", "Moonlight intensity", 1f, "Light intensity nighttime multiplier (moon)");
	}

	private ConfigEntry<T> config<T>(string group, string name, T defaultValue, ConfigDescription description, bool synchronizedSetting = true)
	{
		ConfigEntry<T> val = ((BaseUnityPlugin)this).Config.Bind<T>(group, name, defaultValue, description);
		((ConditionalConfigSync)configSync).AddConfigEntry<T>(val, (ConfigSyncMode)1, synchronizedSetting);
		return val;
	}

	private ConfigEntry<T> config<T>(string group, string name, T defaultValue, string description, bool synchronizedSetting = true)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Expected O, but got Unknown
		return config(group, name, defaultValue, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()), synchronizedSetting);
	}

	private static float GetDayStartFraction()
	{
		return (float)nightLength.Value / 2f / 100f;
	}

	private static bool ControlNightLength()
	{
		return modEnabled.Value && enableDayNightCycle.Value && nightLength.Value != 30 && nightLength.Value != 0;
	}

	private static bool HasAnyEffect(bool indoors)
	{
		if (lightIntensityDayMultiplier.Value != 1f)
		{
			return true;
		}
		if (lightIntensityNightMultiplier.Value != 1f)
		{
			return true;
		}
		if (indoors)
		{
			return indoorLuminanceMultiplier.Value != 1f || fogDensityIndoorsMultiplier.Value != 1f;
		}
		return nightLuminanceMultiplier.Value != 1f || morningLuminanceMultiplier.Value != 1f || dayLuminanceMultiplier.Value != 1f || eveningLuminanceMultiplier.Value != 1f || fogDensityNightMultiplier.Value != 1f || fogDensityMorningMultiplier.Value != 1f || fogDensityDayMultiplier.Value != 1f || fogDensityEveningMultiplier.Value != 1f;
	}
}