Decompiled source of FleetingSeasons v1.1.1

BepInEx/plugins/FleetingSeasons/FleetingSeasons.dll

Decompiled 2 weeks 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FleetingSeasons")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1")]
[assembly: AssemblyProduct("Fleeting Seasons")]
[assembly: AssemblyTitle("FleetingSeasons")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FleetingSeasons
{
	[BepInPlugin("AirenElias.FleetingSeasons", "Fleeting Seasons", "1.1.1")]
	public class FleetingSeasons : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		private readonly Harmony harmony = new Harmony("AirenElias.FleetingSeasons");

		public static bool Enabled = false;

		public static int DaysInSeason = 28;

		public static ConfigEntry<double> SeasonLengthMultiplier;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			SeasonLengthMultiplier = ((BaseUnityPlugin)this).Config.Bind<double>("General", "Season Length", 0.5, "Season length multiplier (e.g. 1 is full 28 days 4 weeks per season, 0.5 is 2 weeks, 0.75 is 3 weeks out of 4)");
			if (SeasonLengthMultiplier.Value > 1.0)
			{
				Logger.LogWarning((object)"Season length modifier can't be set higher than 1");
				SeasonLengthMultiplier.Value = 1.0;
			}
			DaysInSeason = (int)Math.Ceiling((double)DaysInSeason * SeasonLengthMultiplier.Value);
			harmony.PatchAll();
			Logger.LogInfo((object)"Plugin Fleeting Seasons is loaded!");
		}
	}
	[HarmonyPatch]
	public class GameManagerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameManager), "GetCurrentSeason")]
		private static void GetCurrentSeason(GameManager __instance, ref SeasonSO __result)
		{
			NetworkVariable<int> val = Traverse.Create((object)__instance).Field("day").GetValue() as NetworkVariable<int>;
			__result = __instance.seasons[(val.Value - 1) / FleetingSeasons.DaysInSeason % 4];
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameManager), "GetSeasonOnDay")]
		private static void GetSeasonOnDay(GameManager __instance, int day, ref SeasonSO __result)
		{
			__result = __instance.seasons[(day - 1) / FleetingSeasons.DaysInSeason % 4];
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameManager), "GetNormalizedDay")]
		private static void GetNormalizedDay(int day, ref int __result)
		{
			int num = day % FleetingSeasons.DaysInSeason;
			__result = ((num != 0) ? num : FleetingSeasons.DaysInSeason);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameManager), "GetCurrentDay")]
		private static void GetCurrentDay(GameManager __instance, ref int __result)
		{
			int num = (Traverse.Create((object)__instance).Field("day").GetValue() as NetworkVariable<int>).Value % FleetingSeasons.DaysInSeason;
			__result = ((num != 0) ? num : FleetingSeasons.DaysInSeason);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameManager), "GetCurrentYear")]
		private static void GetCurrentYear(GameManager __instance, ref int __result)
		{
			NetworkVariable<int> val = Traverse.Create((object)__instance).Field("day").GetValue() as NetworkVariable<int>;
			__result = (val.Value - 1) / FleetingSeasons.DaysInSeason * 4 + 1;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameManager), "Start")]
		private static void Start(GameManager __instance)
		{
			UIManager.Instance.calendarDates.RemoveRange(FleetingSeasons.DaysInSeason, UIManager.Instance.calendarDates.Count - FleetingSeasons.DaysInSeason);
			RectTransform component = ((Component)((Component)((Component)UIManager.Instance.panelCalendar.transform.GetChild(1)).GetComponent<RectTransform>()).transform.GetChild(1)).GetComponent<RectTransform>();
			for (int i = FleetingSeasons.DaysInSeason; i < ((Transform)component).childCount; i++)
			{
				((Component)((Transform)component).GetChild(i)).gameObject.SetActive(false);
			}
			if (FleetingSeasons.Enabled)
			{
				return;
			}
			foreach (EventSO @event in __instance.events)
			{
				int count = @event.days.Count;
				int num = (int)Math.Ceiling((double)count * FleetingSeasons.SeasonLengthMultiplier.Value);
				if (count > num)
				{
					@event.days.RemoveRange(num, count - num);
				}
				@event.days[0] = (int)Math.Ceiling((double)@event.days[0] * FleetingSeasons.SeasonLengthMultiplier.Value);
				for (int j = 1; j < num; j++)
				{
					@event.days[j] = @event.days[j - 1] + 1;
				}
			}
			FleetingSeasons.Enabled = true;
			FleetingSeasons.Logger.LogInfo((object)("Season length was set to " + FleetingSeasons.DaysInSeason + " days"));
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "AirenElias.FleetingSeasons";

		public const string PLUGIN_NAME = "Fleeting Seasons";

		public const string PLUGIN_VERSION = "1.1.1";
	}
	[HarmonyPatch]
	public class UIManagerPatch
	{
		private static Vector3 CalendarDateDefaultScale;

		private static Vector3 CalendarDateFocusedScale;

		private static Color CalendarDateDefaultColor;

		private static Color CalendarDateFocusedColor;

		private static bool CalendarDateFocused;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIManager), "ToggleCalendarPanel")]
		private static void ToggleCalendarPanel(UIManager __instance)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.panelCalendar.activeInHierarchy)
			{
				CloseAllPanels(__instance);
				return;
			}
			Transform child = ((Transform)((Component)((Component)((Component)__instance.panelCalendar.transform.GetChild(1)).GetComponent<RectTransform>()).transform.GetChild(1)).GetComponent<RectTransform>()).GetChild(GameManager.Instance.GetCurrentDay() - 1);
			Image component = ((Component)child).GetComponent<Image>();
			if (CalendarDateDefaultScale == default(Vector3) || CalendarDateDefaultColor == default(Color))
			{
				CalendarDateDefaultScale = ((Component)child).transform.localScale;
				CalendarDateDefaultColor = ((Graphic)component).color;
				CalendarDateFocusedScale = new Vector3(CalendarDateDefaultScale.x * 1.2f, CalendarDateDefaultScale.y * 1.2f, CalendarDateDefaultScale.z);
				CalendarDateFocusedColor = new Color(CalendarDateDefaultColor.r * 1.005f, CalendarDateDefaultColor.g * 1.01f, CalendarDateDefaultColor.b * 1.2f, CalendarDateDefaultColor.a);
			}
			((Component)child).transform.localScale = CalendarDateFocusedScale;
			((Graphic)component).color = CalendarDateFocusedColor;
			CalendarDateFocused = true;
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIManager), "CloseAllPanels")]
		private static void CloseAllPanels(UIManager __instance)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if (CalendarDateFocused)
			{
				Transform child = ((Transform)((Component)((Component)((Component)__instance.panelCalendar.transform.GetChild(1)).GetComponent<RectTransform>()).transform.GetChild(1)).GetComponent<RectTransform>()).GetChild(GameManager.Instance.GetCurrentDay() - 1);
				Image component = ((Component)child).GetComponent<Image>();
				((Component)child).transform.localScale = CalendarDateDefaultScale;
				((Graphic)component).color = CalendarDateDefaultColor;
				CalendarDateFocused = false;
			}
		}
	}
}