Decompiled source of Big Night v1.0.3

BigNight.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enviro;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BigNight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Big Night")]
[assembly: AssemblyTitle("BigNight")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BigNight
{
	[BepInPlugin("BigNight", "Big Night", "1.0.0")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Log;

		public override void Load()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			Log.LogInfo((object)"Big Night loaded!");
			Harmony val = new Harmony("xoduk.bignight");
			val.PatchAll();
			((BasePlugin)this).AddComponent<BigNightController>();
		}
	}
	[HarmonyPatch(typeof(EnviroTimeModule))]
	public static class SuppressEnviroLog
	{
		[HarmonyPatch(typeof(Debug), "Log", new Type[] { typeof(Object) })]
		public static class SafeIL2CPPLogPatch
		{
			private static bool Prefix(Object message)
			{
				if (message != null && message.ToString().Contains("enviro server time sync"))
				{
					return false;
				}
				return true;
			}
		}
	}
	public class BigNightController : MonoBehaviour
	{
		private const float SunriseMinutes = 4f;

		private const float DayMinutes = 6f;

		private const float SunsetMinutes = 4f;

		private const float NightMinutes = 10f;

		private const float SunriseStart = 4.5f;

		private const float SunriseEnd = 6f;

		private const float DayStart = 6f;

		private const float DayEnd = 18.5f;

		private const float SunsetStart = 18.5f;

		private const float SunsetEnd = 21f;

		private const float NightStart = 21f;

		private const float NightEnd = 28.5f;

		private EnviroTimeModule timeModule;

		private float cycleElapsed;

		private bool initialized;

		public void Update()
		{
			if ((Object)(object)timeModule == (Object)null)
			{
				FindTimeModule();
				return;
			}
			if (!initialized)
			{
				InitializeClock();
			}
			cycleElapsed += Time.deltaTime;
			float num = 24f;
			if (cycleElapsed >= num * 60f)
			{
				cycleElapsed %= num * 60f;
			}
			float timeOfDay = CalculateGameTime(cycleElapsed);
			timeModule.SetTimeOfDay(timeOfDay);
		}

		private void FindTimeModule()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			Il2CppArrayBase<EnviroTimeModule> val = Resources.FindObjectsOfTypeAll<EnviroTimeModule>();
			bool flag = default(bool);
			foreach (EnviroTimeModule item in val)
			{
				if (((Object)item).name == "Time Module(Clone)")
				{
					timeModule = item;
					Plugin.Log.LogInfo((object)"Found Time Module!");
					ManualLogSource log = Plugin.Log;
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(20, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Starting game time: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<float>(item.GetTimeOfDay(), "0.00");
					}
					log.LogInfo(val2);
					break;
				}
			}
		}

		private void InitializeClock()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			initialized = true;
			float timeOfDay = timeModule.GetTimeOfDay();
			cycleElapsed = GameTimeToCyclePosition(timeOfDay);
			ManualLogSource log = Plugin.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(31, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Big Night clock initialized at ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(timeOfDay, "0.00");
			}
			log.LogInfo(val);
		}

		private float CalculateGameTime(float elapsed)
		{
			float num = 240f;
			float num2 = 360f;
			float num3 = 240f;
			float num4 = 600f;
			if (elapsed < num)
			{
				float num5 = elapsed / num;
				return Mathf.Lerp(4.5f, 6f, num5);
			}
			elapsed -= num;
			if (elapsed < num2)
			{
				float num6 = elapsed / num2;
				return Mathf.Lerp(6f, 18.5f, num6);
			}
			elapsed -= num2;
			if (elapsed < num3)
			{
				float num7 = elapsed / num3;
				return Mathf.Lerp(18.5f, 21f, num7);
			}
			elapsed -= num3;
			float num8 = elapsed / num4;
			float num9 = Mathf.Lerp(21f, 28.5f, num8);
			if (num9 >= 24f)
			{
				num9 -= 24f;
			}
			return num9;
		}

		private float GameTimeToCyclePosition(float gameTime)
		{
			float num = 240f;
			float num2 = 360f;
			float num3 = 240f;
			if (gameTime >= 4.5f && gameTime < 6f)
			{
				float num4 = Mathf.InverseLerp(4.5f, 6f, gameTime);
				return num4 * num;
			}
			if (gameTime >= 6f && gameTime < 18.5f)
			{
				float num5 = Mathf.InverseLerp(6f, 18.5f, gameTime);
				return num + num5 * num2;
			}
			if (gameTime >= 18.5f && gameTime < 21f)
			{
				float num6 = Mathf.InverseLerp(18.5f, 21f, gameTime);
				return num + num2 + num6 * num3;
			}
			float num7 = ((!(gameTime >= 21f)) ? (gameTime + 4.5f) : (gameTime - 21f));
			float num8 = num7 / 7.5f;
			return num + num2 + num3 + num8 * 600f;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BigNight";

		public const string PLUGIN_NAME = "Big Night";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}