Decompiled source of AdjustableDayLengthMono v1.1.2

Mods/AdjustableDayLength.Mono.dll

Decompiled 5 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AdjustableDayLength;
using Fxcpds;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using ScheduleOne.DevUtilities;
using ScheduleOne.GameTime;
using ScheduleOne.PlayerScripts;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: MelonID("AdjustableDayLength")]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonInfo(typeof(Mod), "Adjustable Day Length", "1.1.2", "Foxcapades", null)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AdjustableDayLength")]
[assembly: AssemblyConfiguration("Mono")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+354d28714084364f9ba7d627ba284d7fc1211843")]
[assembly: AssemblyProduct("AdjustableDayLength")]
[assembly: AssemblyTitle("AdjustableDayLength")]
[assembly: AssemblyVersion("1.0.0.0")]
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 Fxcpds
{
	public abstract class FxMod : MelonMod
	{
		private static FxMod? instance;

		public static FxMod Instance => instance;

		public override void OnEarlyInitializeMelon()
		{
			instance = this;
		}

		public override void OnInitializeMelon()
		{
			Player.onPlayerSpawned = (Action<Player>)Delegate.Combine(Player.onPlayerSpawned, new Action<Player>(onPlayerSpawned));
		}

		private void onPlayerSpawned(Player player)
		{
			onPlayerLoaded(player);
		}

		protected virtual void onPlayerLoaded(Player player)
		{
		}
	}
	public sealed class NumberValidator<T> : ValueValidator where T : IComparable<T>
	{
		private readonly T min;

		private readonly T max;

		public NumberValidator(T min, T max)
		{
			this.min = min;
			this.max = max;
		}

		public override bool IsValid(object value)
		{
			T val = (T)value;
			return val.CompareTo(min) > -1 && val.CompareTo(max) < 1;
		}

		public override object EnsureValid(object value)
		{
			T val = (T)value;
			if (val.CompareTo(min) < 0)
			{
				return min;
			}
			if (val.CompareTo(max) > 0)
			{
				return max;
			}
			return value;
		}
	}
}
namespace AdjustableDayLength
{
	public class Mod : FxMod
	{
		public const string MOD_NAME = "Adjustable Day Length";

		private const float MIN_MULTIPLIER = 0.1f;

		private const float MAX_MULTIPLIER = 60f;

		private static MelonPreferences_Entry<float>? modifier;

		private static string defaultMelonConfigPath => Path.Combine(MelonEnvironment.UserDataDirectory, "MelonPreferences.cfg");

		public override void OnInitializeMelon()
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory("Adjustable Day Length", "Adjustable Day Length");
			modifier = val.CreateEntry<float>("modifier", 1f, "Day Length Multiplier", "Valid range: 0.1 = 10x faster days - 60 = real world time", false, false, (ValueValidator)(object)new NumberValidator<float>(0.1f, 60f), (string)null);
			((MelonEventBase<LemonAction<float, float>>)(object)modifier.OnEntryValueChanged).Subscribe((LemonAction<float, float>)onPreferenceSaved, 0, false);
			if (getOldValue(out var value))
			{
				((MelonBase)this).LoggerInstance.Msg("copying day length multiplier {0} from an older mod version config", new object[1] { value });
				modifier.Value = value;
			}
			base.OnInitializeMelon();
		}

		protected override void onPlayerLoaded(Player _)
		{
			TimeManagerClean();
		}

		private static void onPreferenceSaved(float _1, float _2)
		{
			TimeManagerClean();
		}

		private static bool getOldValue(out float value)
		{
			value = 0f;
			if (getOldValue("DayLengthModifier", out var value2))
			{
				value = value2;
			}
			if (getOldValue("Day Length Modifier", out var value3))
			{
				value = value3;
			}
			return value > 0f;
		}

		private static bool getOldValue(string category, out float value)
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory(category);
			MelonPreferences_Entry<float> val2 = val.CreateEntry<float>("modifier", value = 0f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			if (val2.Value > 0f)
			{
				value = val2.Value;
			}
			val.DeleteEntry("modifier");
			MelonPreferences.RemoveCategoryFromFile(defaultMelonConfigPath, val.Identifier);
			return value > 0f;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(TimeManager), "Clean")]
		private static void TimeManagerClean()
		{
			TimeManager obj = NetworkSingleton<TimeManager>.Instance;
			if (obj != null)
			{
				obj.SetTimeSpeedMultiplier(1f / modifier.Value);
			}
		}
	}
}