Decompiled source of DayAndNight v1.0.2

DayAndNight.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
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 BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DayAndNight")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("DayAndNight")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace DayAndNight
{
	[BepInPlugin("Azumatt.DayAndNight", "DayAndNight", "1.0.2")]
	public class DayAndNightPlugin : BaseUnityPlugin
	{
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[UsedImplicitly]
			public string? Category;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer;
		}

		private class AcceptableShortcuts : AcceptableValueBase
		{
			public AcceptableShortcuts()
				: base(typeof(KeyboardShortcut))
			{
			}

			public override object Clamp(object value)
			{
				return value;
			}

			public override bool IsValid(object value)
			{
				return true;
			}

			public override string ToDescriptionString()
			{
				return "# Acceptable values: " + string.Join(", ", UnityInput.Current.SupportedKeyCodes);
			}
		}

		internal const string ModName = "DayAndNight";

		internal const string ModVersion = "1.0.2";

		internal const string Author = "Azumatt";

		private const string ModGUID = "Azumatt.DayAndNight";

		private static string ConfigFileName = "Azumatt.DayAndNight.cfg";

		private static string ConfigFileFullPath;

		private readonly Harmony _harmony = new Harmony("Azumatt.DayAndNight");

		public static readonly ManualLogSource DayAndNightLogger;

		internal static ConfigEntry<KeyboardShortcut> FreezeTimeHotkey;

		internal static ConfigEntry<Toggle> FreezeTime;

		internal static ConfigEntry<float> DayModifier;

		internal static ConfigEntry<float> NightModifier;

		internal static ConfigEntry<float> CycleLengthInMinutes;

		internal static ConfigEntry<int> Seconds;

		internal static ConfigEntry<int> Minutes;

		internal static ConfigEntry<int> Hours;

		internal static ConfigEntry<int> Days;

		internal static ConfigEntry<int> Years;

		public void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			FreezeTimeHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("2 - Hotkeys", "Freeze Time Hotkey", new KeyboardShortcut((KeyCode)102, (KeyCode[])(object)new KeyCode[1] { (KeyCode)306 }), "This is the hotkey that will toggle the Freeze Time option. This will only work if the game is not paused.");
			FreezeTime = ((BaseUnityPlugin)this).Config.Bind<Toggle>("1 - Freeze", "Freeze Time", Toggle.Off, "If on, the other values in this section take effect. They will control the time of day that is in the game.");
			Seconds = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Freeze", "Seconds", 0, "If Freeze Time is on, this will control the seconds of the day. 0 is the default, 30 is half a minute, 60 is a minute.");
			Minutes = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Freeze", "Minutes", 0, "If Freeze Time is on, this will control the minutes of the day. 0 is the default, 30 is half an hour, 60 is an hour.");
			Hours = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Freeze", "Hours", 12, "If Freeze Time is on, this will control the hours of the day. 12 noon is the default, 0 is midnight, 24 is midnight");
			Days = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Freeze", "Days", 1, "If Freeze Time is on, this will control the days in your game. 1 is the default");
			Years = ((BaseUnityPlugin)this).Config.Bind<int>("1 - Freeze", "Years", 1, "If Freeze Time is on, this will control the years of your game. 1 is the default.");
			DayModifier = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Modifiers", "Day Modifier", -1f, "If this value is not -1, it will control the length of the day. 1 is normal, 2 is twice as long, 0.5 is half as long.");
			NightModifier = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Modifiers", "Night Modifier", -1f, "If this value is not -1, it will control the length of the night. 1 is normal, 2 is twice as long, 0.5 is half as long.");
			CycleLengthInMinutes = ((BaseUnityPlugin)this).Config.Bind<float>("1 - Modifiers", "Cycle Length In Minutes", -1f, "If this value is not -1, it will control the cycle length of the day. The default for the game is 5 minutes. This will change the length of the day & night cycle. The game states this as the Full 24h cycle in realtime minutes.");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
			SetupWatcher();
		}

		private void Update()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			if (FreezeTimeHotkey.Value.IsKeyDown())
			{
				FreezeTime.Value = ((FreezeTime.Value != Toggle.On) ? Toggle.On : Toggle.Off);
			}
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				DayAndNightLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				DayAndNightLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				DayAndNightLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		internal ConfigEntry<T> TextEntryConfig<T>(string group, string name, T value, string desc)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
			{
				CustomDrawer = TextAreaDrawer
			};
			return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, new ConfigDescription(desc, (AcceptableValueBase)null, new object[1] { configurationManagerAttributes }));
		}

		internal static void TextAreaDrawer(ConfigEntryBase entry)
		{
			GUILayout.ExpandHeight(true);
			GUILayout.ExpandWidth(true);
			entry.BoxedValue = GUILayout.TextArea((string)entry.BoxedValue, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.ExpandWidth(true),
				GUILayout.ExpandHeight(true)
			});
		}

		static DayAndNightPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			DayAndNightLogger = Logger.CreateLogSource("DayAndNight");
			FreezeTimeHotkey = null;
			FreezeTime = null;
			DayModifier = null;
			NightModifier = null;
			CycleLengthInMinutes = null;
			Seconds = null;
			Minutes = null;
			Hours = null;
			Days = null;
			Years = null;
		}
	}
	public static class KeyboardExtensions
	{
		public static bool IsKeyDown(this KeyboardShortcut shortcut)
		{
			//IL_0002: 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)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
			}
			return false;
		}

		public static bool IsKeyHeld(this KeyboardShortcut shortcut)
		{
			//IL_0002: 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)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(EnviroCore), "UpdateTime")]
	internal static class EnviroCoreUpdateTimePatch
	{
		private static void Prefix(EnviroCore __instance)
		{
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			if ((double)Math.Abs(DayAndNightPlugin.DayModifier.Value - -1f) > 0.001)
			{
				if ((double)DayAndNightPlugin.DayModifier.Value < 0.001)
				{
					DayAndNightPlugin.DayModifier.Value = 0.001f;
				}
				__instance.GameTime.dayLengthModifier = DayAndNightPlugin.DayModifier.Value;
			}
			if ((double)Math.Abs(DayAndNightPlugin.NightModifier.Value - -1f) > 0.001)
			{
				if ((double)DayAndNightPlugin.NightModifier.Value < 0.001)
				{
					DayAndNightPlugin.NightModifier.Value = 0.001f;
				}
				__instance.GameTime.nightLengthModifier = DayAndNightPlugin.NightModifier.Value;
			}
			if ((double)Math.Abs(DayAndNightPlugin.CycleLengthInMinutes.Value - -1f) > 0.001)
			{
				if ((double)DayAndNightPlugin.CycleLengthInMinutes.Value < 0.001)
				{
					DayAndNightPlugin.CycleLengthInMinutes.Value = 0.001f;
				}
				__instance.GameTime.cycleLengthInMinutes = DayAndNightPlugin.CycleLengthInMinutes.Value;
			}
			if (DayAndNightPlugin.FreezeTime.Value == DayAndNightPlugin.Toggle.On)
			{
				__instance.GameTime.ProgressTime = (TimeProgressMode)0;
				__instance.GameTime.Seconds = DayAndNightPlugin.Seconds.Value;
				__instance.GameTime.Minutes = DayAndNightPlugin.Minutes.Value;
				__instance.GameTime.Hours = DayAndNightPlugin.Hours.Value;
				__instance.GameTime.Days = DayAndNightPlugin.Days.Value;
				__instance.GameTime.Years = DayAndNightPlugin.Years.Value;
			}
			else
			{
				__instance.GameTime.ProgressTime = (TimeProgressMode)1;
			}
		}
	}
}