Decompiled source of ChooseWeather v1.0.1

ChooseWeather.dll

Decompiled 8 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using ChooseWeather.Patches;
using HarmonyLib;
using TerminalApi;
using TerminalApi.Classes;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ChooseWeather
{
	[BepInPlugin("digjohnsons.ChooseWeather", "Choose Weather", "1.0.0")]
	public class ChooseWeatherBase : BaseUnityPlugin
	{
		private const string modGUIID = "digjohnsons.ChooseWeather";

		private const string modName = "Choose Weather";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("digjohnsons.ChooseWeather");

		private static ChooseWeatherBase instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			mls = Logger.CreateLogSource("digjohnsons.ChooseWeather");
			mls.LogInfo((object)"The mod Choose Weather has awaken.");
			AddDisableModCommand();
			AddWeatherCommand("CLEAR");
			AddWeatherCommand("ECLIPSED");
			AddWeatherCommand("FLOODED");
			AddWeatherCommand("FOGGY");
			AddWeatherCommand("RAINY");
			AddWeatherCommand("STORMY");
			harmony.PatchAll(typeof(ChooseWeather.Patches.ChooseWeather));
		}

		private void AddWeatherCommand(string weather)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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)
			//IL_0066: Expected O, but got Unknown
			TerminalApi.AddCommand(weather, new CommandInfo
			{
				Category = "other",
				Description = "From now on all moon's weather will be " + weather + ".",
				DisplayTextSupplier = () => ChangeWeather(weather)
			}, "weather", true);
		}

		private void AddDisableModCommand()
		{
			//IL_0006: 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)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			TerminalApi.AddCommand("disable", new CommandInfo
			{
				Category = "other",
				Description = "Turns off the ChooseWeatherMod's effects.",
				DisplayTextSupplier = DisableWeatherChanging
			}, "weather", true);
		}

		private string ChangeWeather(string newWeather)
		{
			ChooseWeather.Patches.ChooseWeather.ChangeWeather(newWeather);
			return "Weather will be changed to " + newWeather + ".\n(Starting tomorrow)\n";
		}

		private string DisableWeatherChanging()
		{
			ChooseWeather.Patches.ChooseWeather.ChangeWeather(null);
			return "Weather changing is now disable.\n(Starting tomorrow)\n";
		}
	}
}
namespace ChooseWeather.Patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class ChooseWeather
	{
		private static string actualWeather;

		[HarmonyPatch("SetPlanetsWeather")]
		[HarmonyPostfix]
		private static void UpdateWeather(ref SelectableLevel[] ___levels)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if (actualWeather != null)
			{
				for (int i = 0; i < ___levels.Length; i++)
				{
					___levels[i].currentWeather = (LevelWeatherType)Weather.WeatherStringToEnum(actualWeather);
				}
			}
		}

		public static void ChangeWeather(string newWeather)
		{
			actualWeather = newWeather;
		}
	}
	internal class Weather
	{
		public const string dustClouds = "DUST_CLOUDS";

		public const string rainy = "RAINY";

		public const string stormy = "STORMY";

		public const string foggy = "FOGGY";

		public const string flooded = "FLOODED";

		public const string eclipsed = "ECLIPSED";

		public const string clear = "CLEAR";

		public static int WeatherStringToEnum(string weather)
		{
			return weather switch
			{
				"DUST_CLOUDS" => 0, 
				"RAINY" => 1, 
				"STORMY" => 2, 
				"FOGGY" => 3, 
				"FLOODED" => 4, 
				"ECLIPSED" => 5, 
				_ => -1, 
			};
		}
	}
}