Decompiled source of IShowSeed v0.1.1

IShowSeed.dll

Decompiled 3 days 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 TMPro;
using UnityEngine;
using UnityEngine.Events;
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(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("IShowSeed")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+a5863231a34cdb0b8d65018bf910c69de8c60aac")]
[assembly: AssemblyProduct("IShowSeedPlugin")]
[assembly: AssemblyTitle("IShowSeed")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.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 IShowSeed
{
	[HarmonyPatch(typeof(CL_UIManager), "Update")]
	public static class CL_UIManager_Update_Patcher
	{
		[HarmonyPostfix]
		public static void UpdateDebugMenu(CL_UIManager __instance)
		{
			DebugMenu.UpdateDebugText("starting-seed", $"<color=blue>Starting seed: {IShowSeedPlugin.StartingSeed}");
			if (WorldLoader.initialized)
			{
				DebugMenu.UpdateDebugText("current-seed", $"<color=blue>Current seed: {WorldLoader.instance.seed}");
			}
		}
	}
	[HarmonyPatch(typeof(MenuManager), "Start")]
	public static class MenuManager_Start_Patcher
	{
		[HarmonyPostfix]
		public static void PatchSeedWindow(MenuManager __instance)
		{
			GameObject seedWindow = __instance.seedWindow;
			TextMeshProUGUI component = ((Component)seedWindow.transform.Find("Overview Titles/Title Text")).gameObject.GetComponent<TextMeshProUGUI>();
			TextMeshProUGUI buttonText = ((Component)seedWindow.transform.Find("Tab Selection Hor/Exit/Text (TMP)")).gameObject.GetComponent<TextMeshProUGUI>();
			Button component2 = ((Component)seedWindow.transform.Find("Tab Selection Hor/Exit")).gameObject.GetComponent<Button>();
			TMP_InputField seedPrompt = ((Component)seedWindow.transform.Find("Seed Input")).gameObject.GetComponent<TMP_InputField>();
			if ((Object)(object)buttonText == (Object)null || (Object)(object)seedPrompt == (Object)null || (Object)(object)component2 == (Object)null)
			{
				IShowSeedPlugin.Logger.LogWarning((object)$"button: {component2}\nbuttonText: {buttonText}\nseedPrompt: {seedPrompt}");
				return;
			}
			PatchTitle(component);
			PatchPrompt(seedPrompt);
			PatchButton(component2);
			void PatchButton(Button button)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Expected O, but got Unknown
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Expected O, but got Unknown
				button.onClick = new ButtonClickedEvent();
				((UnityEvent)button.onClick).AddListener((UnityAction)delegate
				{
					//IL_0093: Unknown result type (might be due to invalid IL or missing references)
					if (int.TryParse(seedPrompt.text, out var result) || seedPrompt.text == "")
					{
						IShowSeedPlugin.configPresetSeed.Value = result;
						((BaseUnityPlugin)IShowSeedPlugin.Instance).Config.Save();
						IShowSeedPlugin.Logger.LogInfo((object)$"Set new seed to {result}");
						seedWindow.SetActive(false);
					}
					else
					{
						((TMP_Text)buttonText).text = "Invalid seed";
						((Graphic)buttonText).color = Color.red;
					}
				});
			}
			void PatchPrompt(TMP_InputField prompt)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Expected O, but got Unknown
				prompt.text = IShowSeedPlugin.configPresetSeed.Value.ToString();
				((Graphic)buttonText).color = Color.grey;
				((TMP_Text)buttonText).text = "Save to Config";
				prompt.onValueChanged = new OnChangeEvent();
				((UnityEvent<string>)(object)prompt.onValueChanged).AddListener((UnityAction<string>)delegate
				{
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					((Graphic)buttonText).color = Color.white;
					((TMP_Text)buttonText).text = "Save to Config";
				});
			}
			static void PatchTitle(TextMeshProUGUI title)
			{
				((TMP_Text)title).text = "ENTER SEED";
			}
		}
	}
	[HarmonyPatch(typeof(UT_SeededEnable), "OnEnable")]
	public static class UT_SeededEnable_OnEnable_Patcher
	{
		[HarmonyPrefix]
		public static bool ShowSeedText(UT_SeededEnable __instance)
		{
			TextMeshProUGUI component = ((Component)__instance).gameObject.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).text = $"SEED: {IShowSeedPlugin.StartingSeed}";
			if (WorldLoader.customSeed)
			{
				((TMP_Text)component).text = "PRESET " + ((TMP_Text)component).text;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(WorldLoader), "Awake")]
	public static class WorldLoader_Awake_Patcher
	{
		[HarmonyPrefix]
		public static void StoreStartingSeed(WorldLoader __instance)
		{
			WorldLoader.SetPresetSeed(IShowSeedPlugin.configPresetSeed.Value.ToString());
			IShowSeedPlugin.Logger.LogInfo((object)$"custom preset seed: {IShowSeedPlugin.configPresetSeed.Value}");
		}
	}
	[HarmonyPatch(typeof(WorldLoader), "Initialize")]
	public static class WorldLoader_Initialize_Patcher
	{
		[HarmonyPostfix]
		public static void RememberStartingSeed(WorldLoader __instance)
		{
			IShowSeedPlugin.Logger.LogInfo((object)$"starting seed: {__instance.startingSeed}");
			IShowSeedPlugin.StartingSeed = __instance.startingSeed;
		}
	}
	[BepInPlugin("shishyando.WK.IShowSeed", "IShowSeed", "0.1.0")]
	public class IShowSeedPlugin : BaseUnityPlugin
	{
		private const string GUID = "shishyando.WK.IShowSeed";

		private const string Name = "IShowSeed";

		private const string Version = "0.1.0";

		internal static IShowSeedPlugin Instance;

		internal static ManualLogSource Logger;

		private readonly Harmony Harmony = new Harmony("shishyando.WK.IShowSeed");

		internal static int StartingSeed;

		internal static ConfigEntry<int> configPresetSeed;

		private void Awake()
		{
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			configPresetSeed = ((BaseUnityPlugin)this).Config.Bind<int>("General", "PresetSeed", 0, "Preset seed to use in all gamemodes, `0` to keep the default behaviour");
			Harmony.PatchAll(typeof(WorldLoader_Awake_Patcher));
			Harmony.PatchAll(typeof(WorldLoader_Initialize_Patcher));
			Harmony.PatchAll(typeof(CL_UIManager_Update_Patcher));
			Harmony.PatchAll(typeof(MenuManager_Start_Patcher));
			Harmony.PatchAll(typeof(UT_SeededEnable_OnEnable_Patcher));
			Logger.LogInfo((object)"shishyando.WK.IShowSeed is loaded");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "IShowSeed";

		public const string PLUGIN_NAME = "IShowSeedPlugin";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}