Decompiled source of SeasonChanger v0.1.50

SeasonChanger.dll

Decompiled 7 months ago
using System;
using System.Collections;
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.Configuration;
using GameConsole;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SeasonChanger.Assets;
using SeasonChanger.ConsoleCommands;
using SeasonChanger.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
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.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("SeasonChanger")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("yes")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e557d38323ff79fd2e0d92ce52e4d12d5cea04ec")]
[assembly: AssemblyProduct("SeasonChanger")]
[assembly: AssemblyTitle("SeasonChanger")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SeasonChanger
{
	[BepInPlugin("kekson1a.SeasonChanger", "SeasonChanger", "0.1.5")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		public ConfigEntry<bool> ConfigSaveSeasons;

		public ConfigEntry<int> ConfigLastUsedSeason;

		private void Awake()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)"hi, SeasonChanger of version 0.1.5 is loaded");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Open your console with [F8] and type \"setdate\" to open this mod's menu");
			Object.DontDestroyOnLoad((Object)(object)new GameObject().AddComponent<DateMenu>());
			Object.DontDestroyOnLoad((Object)(object)new GameObject().AddComponent<LoadBundle>());
			new Harmony("kekson1a.SeasonChanger").PatchAll();
			Instance = this;
			LoadConfiguration();
		}

		private void LoadConfiguration()
		{
			ConfigSaveSeasons = ((BaseUnityPlugin)this).Config.Bind<bool>("Options", "SaveSeasons", true, "Toggles saving the season you selected");
			ConfigLastUsedSeason = ((BaseUnityPlugin)this).Config.Bind<int>("Options.Season", "SeasonOverride", 0, "Saved season you selected (uses enum DateMenu.SeasonalDate)");
			DateMenu.Instance.SelectedSeason = (DateMenu.SeasonalDate)ConfigLastUsedSeason.Value;
			DateMenu.Instance.SaveSeason = ConfigSaveSeasons.Value;
		}

		public void PrintError(string message)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)message);
		}
	}
	internal class PluginInfo
	{
		public const string GUID = "kekson1a.SeasonChanger";

		public const string NAME = "SeasonChanger";

		public const string VERSION = "0.1.5";
	}
	internal class RealDate
	{
		public static DateTime Now => DateTime.UtcNow + TimeZoneInfo.Local.GetUtcOffset(DateTime.UtcNow);
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "SeasonChanger";

		public const string PLUGIN_NAME = "SeasonChanger";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace SeasonChanger.UI
{
	public class DateMenu : MonoBehaviour
	{
		public enum SeasonalDate
		{
			None,
			Easter,
			Halloween,
			Christmas,
			AprilFools
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__11_1;

			internal void <Build>b__11_1()
			{
				SceneHelper.LoadScene("Main Menu", false);
			}
		}

		public static DateMenu Instance;

		public SeasonalDate SelectedSeason;

		public bool SaveSeason;

		private GameObject seasonMenu;

		private Canvas seasonCanvas;

		private Button reloadMenuButton;

		private TMP_Dropdown selectSeason;

		private Toggle saveSeasonToggle;

		private void Awake()
		{
			Instance = this;
			SceneManager.sceneLoaded += SceneLoaded;
			LoadBundle.OnBundleLoaded += OnBundleLoaded;
		}

		private void SceneLoaded(Scene scene, LoadSceneMode loadSceneMode)
		{
			if (!((Object)(object)reloadMenuButton == (Object)null))
			{
				if (SceneHelper.CurrentScene == "Main Menu")
				{
					((Component)reloadMenuButton).gameObject.SetActive(true);
				}
				else
				{
					((Component)reloadMenuButton).gameObject.SetActive(false);
				}
			}
		}

		private void OnBundleLoaded(AssetBundle bundle)
		{
			((MonoBehaviour)this).StartCoroutine(Build(bundle));
		}

		private IEnumerator Build(AssetBundle bundle)
		{
			AssetBundleRequest assetLoadRequest = bundle.LoadAssetAsync<GameObject>("SeasonCanvas");
			yield return assetLoadRequest;
			Object asset = assetLoadRequest.asset;
			GameObject seasonCanvasObj = (GameObject)(object)((asset is GameObject) ? asset : null);
			seasonCanvas = seasonCanvasObj.GetComponent<Canvas>();
			seasonCanvas = Object.Instantiate<Canvas>(seasonCanvas);
			seasonCanvas.sortingOrder = 99;
			((Component)seasonCanvas).gameObject.SetActive(false);
			Object.DontDestroyOnLoad((Object)(object)seasonCanvas);
			seasonMenu = ((Component)((Component)seasonCanvas).transform.Find("SeasonMenu")).gameObject;
			seasonMenu.AddComponent<HudOpenEffect>();
			((UnityEvent)((Component)seasonMenu.transform.Find("Border/Close")).GetComponent<Button>().onClick).AddListener((UnityAction)delegate
			{
				((Component)seasonCanvas).gameObject.SetActive(false);
			});
			reloadMenuButton = ((Component)seasonMenu.transform.Find("Layout/ReloadMenu")).GetComponent<Button>();
			ButtonClickedEvent onClick = reloadMenuButton.onClick;
			object obj = <>c.<>9__11_1;
			if (obj == null)
			{
				UnityAction val = delegate
				{
					SceneHelper.LoadScene("Main Menu", false);
				};
				<>c.<>9__11_1 = val;
				obj = (object)val;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			selectSeason = ((Component)seasonMenu.transform.Find("Layout/SeasonOverrideDropdown/Dropdown")).GetComponent<TMP_Dropdown>();
			((UnityEvent<int>)(object)selectSeason.onValueChanged).AddListener((UnityAction<int>)SeasonDropdown);
			saveSeasonToggle = ((Component)seasonMenu.transform.Find("Layout/SaveSeason")).GetComponent<Toggle>();
			((UnityEvent<bool>)(object)saveSeasonToggle.onValueChanged).AddListener((UnityAction<bool>)SaveSeasonToggle);
			TriggerLoadConfig();
		}

		private void SeasonDropdown(int seasonalDate)
		{
			SelectedSeason = (SeasonalDate)seasonalDate;
			if (SaveSeason)
			{
				Plugin.Instance.ConfigLastUsedSeason.Value = seasonalDate;
			}
		}

		private void SaveSeasonToggle(bool doSave)
		{
			if (!SaveSeason)
			{
				Plugin.Instance.ConfigLastUsedSeason.Value = 0;
			}
			if (SaveSeason)
			{
				Plugin.Instance.ConfigLastUsedSeason.Value = (int)SelectedSeason;
			}
		}

		public void OpenSeasonMenu()
		{
			((Component)seasonCanvas).gameObject.SetActive(true);
		}

		public void TriggerLoadConfig()
		{
			saveSeasonToggle.isOn = SaveSeason;
			if (SaveSeason)
			{
				selectSeason.value = (int)SelectedSeason;
			}
		}
	}
}
namespace SeasonChanger.Patches
{
	[HarmonyPatch]
	public class ConsolePatch
	{
		[HarmonyPatch(typeof(Console), "Awake")]
		private static void Postfix(Console __instance)
		{
			__instance.RegisterCommand((ICommand)(object)new OpenSeasonMenu());
		}
	}
	[HarmonyPatch]
	public class DateTimeNow
	{
		[HarmonyPatch(typeof(DateTime), "get_Now")]
		private static bool Prefix(ref DateTime __result)
		{
			if (DateMenu.Instance.SelectedSeason == DateMenu.SeasonalDate.None)
			{
				return true;
			}
			__result = GetPatchedDate();
			return false;
		}

		public static DateTime GetPatchedDate()
		{
			DateTime result = RealDate.Now;
			switch (DateMenu.Instance.SelectedSeason)
			{
			case DateMenu.SeasonalDate.Easter:
				result = GetEaster(result.Year);
				break;
			case DateMenu.SeasonalDate.Halloween:
				result = new DateTime(result.Year, 10, 31);
				break;
			case DateMenu.SeasonalDate.Christmas:
				result = new DateTime(result.Year, 12, 25);
				break;
			case DateMenu.SeasonalDate.AprilFools:
				result = new DateTime(result.Year, 4, 1);
				break;
			}
			return result;
		}

		private static DateTime GetEaster(int year)
		{
			int num = year % 19;
			int num2 = year / 100;
			int num3 = (num2 - num2 / 4 - (8 * num2 + 13) / 25 + 19 * num + 15) % 30;
			int num4 = num3 - num3 / 28 * (1 - num3 / 28 * (29 / (num3 + 1)) * ((21 - num) / 11));
			int num5 = num4 - (year + year / 4 + num4 + 2 - num2 + num2 / 4) % 7;
			int num6 = 3 + (num5 + 40) / 44;
			int day = num5 + 28 - 31 * (num6 / 4);
			return new DateTime(year, num6, day);
		}
	}
	[HarmonyPatch]
	public class SandboxSaverPatch
	{
		[HarmonyPatch(typeof(SandboxSaver), "QuickSave")]
		private static bool Prefix(ref SandboxSaver __instance)
		{
			if (DateMenu.Instance.SelectedSeason != 0)
			{
				__instance.Save($"{RealDate.Now.Year}-{RealDate.Now.Month}-{RealDate.Now.Day} {RealDate.Now.Hour}-{RealDate.Now.Minute}-{RealDate.Now.Second}");
				return false;
			}
			return true;
		}
	}
}
namespace SeasonChanger.ConsoleCommands
{
	internal class OpenSeasonMenu : ICommand
	{
		public string Name => "Setdate";

		public string Description => "Command for opening the 'SET DATE' menu (SeasonChanger mod)";

		public string Command => "setdate";

		public void Execute(Console con, string[] args)
		{
			DateMenu.Instance.OpenSeasonMenu();
		}
	}
}
namespace SeasonChanger.Assets
{
	public class LoadBundle : MonoBehaviour
	{
		public delegate void BundleLoaded(AssetBundle bundle);

		private AssetBundle _assetBundle;

		public static event BundleLoaded OnBundleLoaded;

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(GetBundleAsync());
		}

		private IEnumerator GetBundleAsync()
		{
			Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("SeasonChanger.resources.season_menu");
			AssetBundleCreateRequest bundleLoadRequest = AssetBundle.LoadFromStreamAsync(stream);
			yield return bundleLoadRequest;
			AssetBundle loadedBundle = bundleLoadRequest.assetBundle;
			if ((Object)(object)loadedBundle != (Object)null)
			{
				_assetBundle = loadedBundle;
				yield return loadedBundle.LoadAssetAsync("SeasonMenu");
				LoadBundle.OnBundleLoaded?.Invoke(_assetBundle);
			}
			else
			{
				Plugin.Instance.PrintError("Failed to load the asset bundle!");
			}
		}
	}
}