Decompiled source of EndOfDayCountdown V2 v1.0.0

NoteBoxz.EndOfDayCountdownV2.dll

Decompiled 4 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NoteBoxz.EndOfDayCountdownV2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c28235bdeadcda3e70223fcc5506bdf8864028bb")]
[assembly: AssemblyProduct("EndOfDayCountdownV2")]
[assembly: AssemblyTitle("NoteBoxz.EndOfDayCountdownV2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 LCcountdownMod2
{
	public static class AssetLoader
	{
		private static AssetBundle? _assetBundle;

		public static AssetBundle LoadAssetBundle()
		{
			if ((Object)(object)_assetBundle == (Object)null)
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				if (directoryName == null)
				{
					throw new InvalidOperationException("Unable to determine assembly location.");
				}
				string text = Path.Combine(directoryName, "endofdaycountdownv2");
				_assetBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_assetBundle == (Object)null)
				{
					throw new InvalidOperationException("Failed to load endofdaycountdownv2 AssetBundle.");
				}
			}
			return _assetBundle;
		}

		public static T LoadAsset<T>(string assetName) where T : Object
		{
			if (!assetName.EndsWith(".asset") && !assetName.EndsWith(".prefab") && !assetName.EndsWith(".wav") && !assetName.EndsWith(".mat") && !assetName.EndsWith(".ogg") && !assetName.EndsWith(".mp3") && !assetName.EndsWith(".mp4") && !assetName.EndsWith(".anim") && !assetName.EndsWith(".png"))
			{
				assetName += ".asset";
			}
			AssetBundle val = LoadAssetBundle();
			T val2 = val.LoadAsset<T>(assetName);
			if (!val.Contains(assetName))
			{
				throw new InvalidOperationException("Asset not found in bundle: " + assetName);
			}
			if ((Object)(object)val2 == (Object)null)
			{
				throw new InvalidOperationException("Failed to load asset: " + assetName + ". Asset exists in bundle but couldn't be loaded.");
			}
			return val2;
		}
	}
	public class Countdowner : MonoBehaviour
	{
		public AudioSource SFX;

		public TMP_Text TXT;

		public Image Sprite;

		public Animator anim;

		public void Start()
		{
			SetColors();
		}

		public void Count(string TXT5REAL, int TextSize)
		{
			anim.Play("CountDown");
			SFX.Play();
			TXT.text = TXT5REAL;
			TXT.fontSize = TextSize;
		}

		public void SetColors()
		{
			//IL_000c: 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)
			((Graphic)TXT).color = ParseColor(LCcountdownMod2.TextColor);
			((Graphic)Sprite).color = ParseColor(LCcountdownMod2.CircleColor);
		}

		private static Color ParseColor(string colorString)
		{
			//IL_00a3: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			string[] array = colorString.Trim('(', ')').Split(',');
			if (array.Length == 4 && int.TryParse(array[0], out var result) && int.TryParse(array[1], out var result2) && int.TryParse(array[2], out var result3) && int.TryParse(array[3], out var result4))
			{
				return new Color((float)result / 255f, (float)result2 / 255f, (float)result3 / 255f, (float)result4 / 255f);
			}
			LCcountdownMod2.Logger.LogWarning((object)("Unable to parse color config!!!: Input " + colorString + " The input should be somthing like (000,000,000,000) for (R,G,B,A)"));
			return Color.white;
		}
	}
	[BepInPlugin("NoteBoxz.EndOfDayCountdownV2", "EndOfDayCountdownV2", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LCcountdownMod2 : BaseUnityPlugin
	{
		public static bool DebugMode = false;

		public static bool SpawnCountdownInfrountOfUI;

		public static bool StartCountdownWhenShipLeaveEarly;

		public static bool StopCountdownAfter12Am;

		public static bool StopCountdownAfterDeath;

		public static bool StopCountdownAfterShipLeaves;

		public static bool StopCountdownAfterTwelve;

		public static GameObject countdownPrefab;

		public static Countdowner CountDownInstace;

		public static string TextColor = "(214,98,41,255)";

		public static string CircleColor = "(214,98,41,255)";

		public static string[] Txts = new string[11]
		{
			"10", "9", "8", "7", "6", "5", "4", "3", "2", "1",
			"0"
		};

		public static int[] TxtSizes = new int[11]
		{
			36, 36, 36, 36, 36, 36, 36, 36, 36, 36,
			36
		};

		private ConfigEntry<string>[] txtConfigs;

		private ConfigEntry<int>[] txtSizeConfigs;

		public static LCcountdownMod2 Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			InitalizeAssets();
			Patch();
			BindConfigs();
			Logger.LogInfo((object)"NoteBoxz.EndOfDayCountdownV2 v1.0.0 has loaded!");
		}

		internal static void InitalizeAssets()
		{
			countdownPrefab = AssetLoader.LoadAsset<GameObject>("Assets/CountDownAssets/Countdown.prefab");
			Countdowner countdowner = countdownPrefab.AddComponent<Countdowner>();
			countdowner.anim = ((Component)countdowner).GetComponent<Animator>();
			countdowner.SFX = ((Component)countdownPrefab.transform.Find("SFX")).GetComponent<AudioSource>();
			countdowner.TXT = ((Component)countdownPrefab.transform.Find("Image/Number")).GetComponent<TMP_Text>();
			countdowner.Sprite = ((Component)countdownPrefab.transform.Find("Image")).GetComponent<Image>();
		}

		public void BindConfigs()
		{
			ConfigEntry<string> textColorConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "Text Color", "(214,98,41,255)", "Color for the text. Format: (R,G,B,A)");
			ConfigEntry<string> circleColorConfig = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "Circle Color", "(214,98,41,255)", "Color for the circle. Format: (R,G,B,A)");
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Countdown", "Start Countdown When Ship Leaves Early", true, "Start the countdown when the ship leaves early");
			ConfigEntry<bool> val2 = ((BaseUnityPlugin)this).Config.Bind<bool>("Countdown", "Stop Countdown After 12 AM", false, "Stop the countdown after 12 AM");
			ConfigEntry<bool> val3 = ((BaseUnityPlugin)this).Config.Bind<bool>("Countdown", "Stop Countdown After Death", true, "Stop the countdown after death");
			ConfigEntry<bool> val4 = ((BaseUnityPlugin)this).Config.Bind<bool>("Countdown", "Stop Countdown After Ship Leaves", true, "Stop the countdown after the ship leaves");
			ConfigEntry<bool> val5 = ((BaseUnityPlugin)this).Config.Bind<bool>("Countdown", "Stop Countdown After Twelve", true, "Stop the countdown after twelve");
			ConfigEntry<bool> val6 = ((BaseUnityPlugin)this).Config.Bind<bool>("Countdown", "Show coundown in front", false, "Spawns the countdown infront of the main UI");
			txtConfigs = new ConfigEntry<string>[Txts.Length];
			for (int i = 0; i < Txts.Length; i++)
			{
				int num = Txts.Length - 1 - i;
				txtConfigs[i] = ((BaseUnityPlugin)this).Config.Bind<string>("Countdown Text", $"Text {num}", Txts[i], $"Text to display for countdown step {num}");
				int index = i;
				txtConfigs[i].SettingChanged += delegate
				{
					Txts[index] = txtConfigs[index].Value;
				};
			}
			txtSizeConfigs = new ConfigEntry<int>[TxtSizes.Length];
			for (int j = 0; j < TxtSizes.Length; j++)
			{
				int num2 = TxtSizes.Length - 1 - j;
				txtSizeConfigs[j] = ((BaseUnityPlugin)this).Config.Bind<int>("Countdown Text Sizes", $"Size {num2}", TxtSizes[j], $"Font size for countdown step {num2}");
				int index2 = j;
				txtSizeConfigs[j].SettingChanged += delegate
				{
					TxtSizes[index2] = txtSizeConfigs[index2].Value;
				};
			}
			for (int k = 0; k < Txts.Length; k++)
			{
				Txts[k] = txtConfigs[k].Value;
				TxtSizes[k] = txtSizeConfigs[k].Value;
			}
			TextColor = textColorConfig.Value;
			CircleColor = circleColorConfig.Value;
			StartCountdownWhenShipLeaveEarly = val.Value;
			StopCountdownAfter12Am = val2.Value;
			StopCountdownAfterDeath = val3.Value;
			StopCountdownAfterShipLeaves = val4.Value;
			StopCountdownAfterTwelve = val5.Value;
			SpawnCountdownInfrountOfUI = val6.Value;
			textColorConfig.SettingChanged += delegate
			{
				TextColor = textColorConfig.Value;
				if ((Object)(object)CountDownInstace != (Object)null)
				{
					CountDownInstace.SetColors();
				}
			};
			circleColorConfig.SettingChanged += delegate
			{
				CircleColor = circleColorConfig.Value;
				CountDownInstace.SetColors();
			};
			if (IsDependencyLoaded("ainavt.lc.lethalconfig"))
			{
				BindLethalConfigs(textColorConfig, circleColorConfig, val, val2, val3, val4, val5, val6);
			}
		}

		public void BindLethalConfigs(ConfigEntry<string> textColorConfig, ConfigEntry<string> circleColorConfig, ConfigEntry<bool> startCountdownWhenShipLeaveEarlyConfig, ConfigEntry<bool> stopCountdownAfter12AmConfig, ConfigEntry<bool> stopCountdownAfterDeathConfig, ConfigEntry<bool> stopCountdownAfterShipLeavesConfig, ConfigEntry<bool> stopCountdownAfterTwelveConfig, ConfigEntry<bool> SCDIFOUI)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//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_002f: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0054: 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_0066: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00ca: 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_00dc: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Expected O, but got Unknown
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Expected O, but got Unknown
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: 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_0183: Expected O, but got Unknown
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Expected O, but got Unknown
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Expected O, but got Unknown
			TextInputFieldConfigItem val = new TextInputFieldConfigItem(textColorConfig, new TextInputFieldOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
			TextInputFieldConfigItem val2 = new TextInputFieldConfigItem(circleColorConfig, new TextInputFieldOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
			BoolCheckBoxConfigItem val3 = new BoolCheckBoxConfigItem(startCountdownWhenShipLeaveEarlyConfig, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3);
			BoolCheckBoxConfigItem val4 = new BoolCheckBoxConfigItem(stopCountdownAfter12AmConfig, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4);
			BoolCheckBoxConfigItem val5 = new BoolCheckBoxConfigItem(stopCountdownAfterDeathConfig, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val5);
			BoolCheckBoxConfigItem val6 = new BoolCheckBoxConfigItem(stopCountdownAfterShipLeavesConfig, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val6);
			BoolCheckBoxConfigItem val7 = new BoolCheckBoxConfigItem(stopCountdownAfterTwelveConfig, new BoolCheckBoxOptions
			{
				RequiresRestart = false
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val7);
			BoolCheckBoxConfigItem val8 = new BoolCheckBoxConfigItem(SCDIFOUI, new BoolCheckBoxOptions
			{
				RequiresRestart = true
			});
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val8);
			for (int i = 0; i < txtConfigs.Length; i++)
			{
				int num = txtConfigs.Length - 1 - i;
				TextInputFieldConfigItem val9 = new TextInputFieldConfigItem(txtConfigs[i], new TextInputFieldOptions
				{
					RequiresRestart = false,
					Name = $"Text {num}"
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val9);
			}
			for (int j = 0; j < txtSizeConfigs.Length; j++)
			{
				int num2 = txtSizeConfigs.Length - 1 - j;
				ConfigEntry<int> obj = txtSizeConfigs[j];
				IntInputFieldOptions val10 = new IntInputFieldOptions
				{
					RequiresRestart = false
				};
				((BaseRangeOptions<int>)val10).Min = 1;
				((BaseRangeOptions<int>)val10).Max = 100;
				((BaseOptions)val10).Name = $"Size {num2}";
				IntInputFieldConfigItem val11 = new IntInputFieldConfigItem(obj, val10);
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val11);
			}
		}

		public static bool IsDependencyLoaded(string pluginGUID)
		{
			return Chainloader.PluginInfos.ContainsKey(pluginGUID);
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("NoteBoxz.EndOfDayCountdownV2");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	internal class HUDManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void MakeCountdown(HUDManager __instance)
		{
			LCcountdownMod2.CountDownInstace = Object.Instantiate<GameObject>(LCcountdownMod2.countdownPrefab, __instance.HUDContainer.transform.parent).GetComponent<Countdowner>();
			Transform val = __instance.HUDContainer.transform.parent.Find("Panel");
			if ((Object)(object)val != (Object)null && !LCcountdownMod2.SpawnCountdownInfrountOfUI)
			{
				((Component)LCcountdownMod2.CountDownInstace).transform.SetSiblingIndex(val.GetSiblingIndex() + 1);
			}
			else if (!LCcountdownMod2.SpawnCountdownInfrountOfUI)
			{
				LCcountdownMod2.Logger.LogWarning((object)"No 'pannle' found");
			}
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	internal class TimeOfDayUpdatePatch
	{
		private static bool CountingDown;

		private static float DownTimer = 3f;

		private static int Number;

		private static SelectableLevel PatchcurrentLevel;

		private static InputAction keyAction = new InputAction((string)null, (InputActionType)1, "<Keyboard>/5", (string)null, (string)null, (string)null);

		private static float DebugTimer;

		private static float PatchGlobalTime;

		private static float PatchTotalTime;

		private static float EarlyCountDownTime;

		private static float EarlyCountDownDuration = 46.5f;

		private static int PlayersInMatch;

		private static bool DisableDisabler = false;

		private static bool LeavingEarly;

		public static float duration = 42.5f;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void CountDownPatch(ref float ___currentDayTime, ref SelectableLevel ___currentLevel, ref float ___normalizedTimeOfDay, ref float ___totalTime, ref int ___numberOfHours, ref float ___globalTime, ref int ___votesForShipToLeaveEarly)
		{
			PatchGlobalTime = ___globalTime;
			PatchcurrentLevel = ___currentLevel;
			PatchTotalTime = ___totalTime;
			PlayersInMatch = StartOfRound.Instance.connectedPlayersAmount + 1;
			int num = ((PlayersInMatch <= 1) ? 1 : (StartOfRound.Instance.connectedPlayersAmount + 1 - StartOfRound.Instance.livingPlayers));
			if (LCcountdownMod2.DebugMode)
			{
				if (DebugTimer > 0f)
				{
					DebugTimer -= Time.deltaTime;
				}
				else
				{
					Debug.Log((object)"-GAMETIME-");
					Debug.Log((object)("ClockTime " + GetClock(___normalizedTimeOfDay, ___numberOfHours, createNewLine: false)));
					Debug.Log((object)("NormalizedDayTime: " + ___normalizedTimeOfDay));
					Debug.Log((object)("CurrentDayTime: " + ___currentDayTime));
					Debug.Log((object)("NumberOfHours: " + ___numberOfHours));
					Debug.Log((object)("TotalTime " + ___totalTime));
					Debug.Log((object)("StartingCountdown At: " + (LeavingEarly ? GetClock(EarlyCountDownTime / ___totalTime + 0.1f, ___numberOfHours, createNewLine: false) : GetClock(___currentDayTime - duration / ___totalTime, ___numberOfHours, createNewLine: false))));
					Debug.Log((object)"-COUNTDOWN-");
					Debug.Log((object)("EarlyCountDownTime: " + EarlyCountDownTime));
					Debug.Log((object)("LeavingEarly: " + LeavingEarly));
					Debug.Log((object)("CountingDown: " + CountingDown));
					Debug.Log((object)("DownTimer: " + DownTimer));
					Debug.Log((object)("Number: " + Number));
					Debug.Log((object)$"Current EarlyCountDownTime: {EarlyCountDownTime}, CurrentDayTime: {___currentDayTime}, LeavingEarly: {LeavingEarly}");
					DebugTimer = 0.1f;
				}
				keyAction.Enable();
				keyAction.performed += delegate
				{
					DisableDisabler = true;
					DownTimer = 3f;
					Number = 0;
					CountingDown = true;
					LCcountdownMod2.CountDownInstace.Count(LCcountdownMod2.Txts[Number], LCcountdownMod2.TxtSizes[Number]);
					Number++;
					DownTimer = 3f;
				};
			}
			if ((Object)(object)___currentLevel != (Object)null)
			{
				float num2 = ConvertSecondsToGameTime(duration, ___currentLevel);
				float num3 = ___totalTime - num2;
				if (___currentDayTime >= num3 && ___currentDayTime <= num3 + ConvertSecondsToGameTime(3f, ___currentLevel) && !CountingDown)
				{
					if ((___currentDayTime >= 1079f && LCcountdownMod2.StopCountdownAfterTwelve && !DisableDisabler) || (StartOfRound.Instance.shipIsLeaving && LCcountdownMod2.StopCountdownAfterShipLeaves && !DisableDisabler) || (GameNetworkManager.Instance.localPlayerController.isPlayerDead && LCcountdownMod2.StopCountdownAfterDeath))
					{
						return;
					}
					StartCountdown(___currentLevel);
				}
			}
			if ((Object)(object)___currentLevel != (Object)null && ___currentDayTime >= EarlyCountDownTime && ___currentDayTime <= EarlyCountDownTime + ConvertSecondsToGameTime(3f, ___currentLevel) && LCcountdownMod2.StartCountdownWhenShipLeaveEarly && LeavingEarly && !CountingDown)
			{
				if ((___currentDayTime >= 1079f && LCcountdownMod2.StopCountdownAfterTwelve && !DisableDisabler) || (StartOfRound.Instance.shipIsLeaving && LCcountdownMod2.StopCountdownAfterShipLeaves && !DisableDisabler) || (GameNetworkManager.Instance.localPlayerController.isPlayerDead && LCcountdownMod2.StopCountdownAfterDeath))
				{
					return;
				}
				StartCountdown(___currentLevel);
			}
			if (CountingDown)
			{
				if (DownTimer > 0f)
				{
					DownTimer -= Time.deltaTime;
				}
				else if (Number < LCcountdownMod2.Txts.Length)
				{
					LCcountdownMod2.CountDownInstace.Count(LCcountdownMod2.Txts[Number], LCcountdownMod2.TxtSizes[Number]);
					Number++;
					DownTimer = ConvertGameTimeToSeconds(2.6f, ___currentLevel);
				}
				else
				{
					StopCountdown();
				}
				if (___currentDayTime >= 1079f && LCcountdownMod2.StopCountdownAfterTwelve && !DisableDisabler)
				{
					StopCountdown();
				}
				if (StartOfRound.Instance.shipIsLeaving && LCcountdownMod2.StopCountdownAfterShipLeaves && !DisableDisabler)
				{
					StopCountdown();
				}
				if (GameNetworkManager.Instance.localPlayerController.isPlayerDead && LCcountdownMod2.StopCountdownAfterDeath)
				{
					StopCountdown();
				}
			}
		}

		[HarmonyPatch("SetShipLeaveEarlyClientRpc")]
		[HarmonyPostfix]
		public static void PredectShipCountdown(TimeOfDay __instance, float timeToLeaveEarly, int votes)
		{
			float num = ConvertSecondsToGameTime(duration, __instance.currentLevel);
			EarlyCountDownTime = timeToLeaveEarly * __instance.totalTime - num;
			LeavingEarly = true;
			Debug.Log((object)$"EarlyCountDownTime calculated: {EarlyCountDownTime}. ShipLeavePerdiction: {timeToLeaveEarly * __instance.totalTime}, duration in game time: {num}");
		}

		public static float ConvertGameTimeToSeconds(float gameTime, SelectableLevel level)
		{
			return gameTime / level.DaySpeedMultiplier;
		}

		public static float ConvertSecondsToGameTime(float seconds, SelectableLevel level)
		{
			return seconds * level.DaySpeedMultiplier;
		}

		private static void StartCountdown(SelectableLevel currentLevel)
		{
			DisableDisabler = false;
			DownTimer = ConvertGameTimeToSeconds(2.6f, currentLevel);
			Number = 0;
			CountingDown = true;
			LCcountdownMod2.CountDownInstace.Count(LCcountdownMod2.Txts[Number], LCcountdownMod2.TxtSizes[Number]);
			Number++;
		}

		public static void StopCountdown()
		{
			Number = 0;
			DownTimer = 0f;
			CountingDown = false;
			DisableDisabler = false;
			LeavingEarly = false;
		}

		public static string GetClock(float timeNormalized, float numberOfHours, bool createNewLine = true)
		{
			int num = (int)(timeNormalized * (60f * numberOfHours)) + 360;
			int num2 = (int)Mathf.Floor((float)(num / 60));
			string text = "";
			string text2 = "";
			text = (createNewLine ? "\n" : " ");
			text2 = text + "AM";
			if (num2 >= 24)
			{
				return "12:00\nAM";
			}
			text2 = ((num2 >= 12) ? (text + "PM") : (text + "AM"));
			if (num2 > 12)
			{
				num2 %= 12;
			}
			int num3 = num % 60;
			return $"{num2:00}:{num3:00}".TrimStart(new char[1] { '0' }) + text2;
		}

		public static float PlanetTime()
		{
			return (PatchGlobalTime + PatchcurrentLevel.OffsetFromGlobalTime) * PatchcurrentLevel.DaySpeedMultiplier % (PatchTotalTime + 1f);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.EndOfDayCountdownV2";

		public const string PLUGIN_NAME = "EndOfDayCountdownV2";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}