Decompiled source of PikminStyledClock v1.1.1

NoteBoxz.PikminStyledClock.dll

Decompiled 3 weeks ago
using System;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LCPikminClock.Patches;
using LethalConfig;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NoteBoxz.PikminStyledClock")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+f2802eb79256f0a4140e2b63ea38f9b4d6daa246")]
[assembly: AssemblyProduct("LCPikminClock")]
[assembly: AssemblyTitle("NoteBoxz.PikminStyledClock")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 LCPikminClock
{
	public static class AssetLoader
	{
		private static AssetBundle? _assetBundle;

		public static AssetBundle LoadAssetBundle()
		{
			if ((Object)(object)_assetBundle == (Object)null)
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				if (directoryName == null)
				{
					throw new InvalidOperationException("Unable to determine assembly location.");
				}
				string text = Path.Combine(directoryName, "pminclockassets");
				_assetBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_assetBundle == (Object)null)
				{
					throw new InvalidOperationException("Failed to load pminclock AssetBundle.");
				}
			}
			return _assetBundle;
		}

		public static T LoadAsset<T>(string assetName) where T : Object
		{
			if (!assetName.EndsWith(".asset") && !assetName.EndsWith(".prefab") && !assetName.EndsWith(".wav") && !assetName.EndsWith(".mat") && !assetName.EndsWith(".ogg") && !assetName.EndsWith(".mp3") && !assetName.EndsWith(".mp4") && !assetName.EndsWith(".anim") && !assetName.EndsWith(".png"))
			{
				assetName += ".asset";
			}
			AssetBundle val = LoadAssetBundle();
			T val2 = val.LoadAsset<T>(assetName);
			if (!val.Contains(assetName))
			{
				throw new InvalidOperationException("Asset not found in bundle: " + assetName);
			}
			if ((Object)(object)val2 == (Object)null)
			{
				throw new InvalidOperationException("Failed to load asset: " + assetName + ". Asset exists in bundle but couldn't be loaded.");
			}
			return val2;
		}
	}
	[BepInPlugin("NoteBoxz.PikminStyledClock", "LCPikminClock", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LCPikminClock : BaseUnityPlugin
	{
		public enum ClockGen
		{
			Pikmin,
			Pikmin4
		}

		private static AssetBundle? _assetBundle;

		public static GameObject ClockUI;

		public static GameObject Clock4UI;

		public static ConfigEntry<bool> ShowTime;

		public static ConfigEntry<string> IconColor;

		public static ConfigEntry<string> DotsColor;

		public static ConfigEntry<string> LinesColor;

		public static ConfigEntry<string> TimeColor;

		public static ConfigEntry<ClockGen> ClockStyle;

		public static LCPikminClock Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			Patch();
			BindConfigs();
			LoadAssetBundle();
			if (IsDependencyLoaded("ainavt.lc.lethalconfig"))
			{
				BindLCConfigs();
			}
			ClockUI = _assetBundle.LoadAsset<GameObject>("Assets/ClockAssets/PikminTime.prefab");
			Clock4UI = _assetBundle.LoadAsset<GameObject>("Assets/4ClockAssets/PikminTime.prefab");
			Logger.LogInfo((object)"NoteBoxz.PikminStyledClock v1.1.1 has loaded!");
		}

		public static AssetBundle LoadAssetBundle()
		{
			if ((Object)(object)_assetBundle == (Object)null)
			{
				string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
				if (directoryName == null)
				{
					throw new InvalidOperationException("Unable to determine assembly location.");
				}
				string text = Path.Combine(directoryName, "pminclockassets");
				_assetBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_assetBundle == (Object)null)
				{
					throw new InvalidOperationException("Failed to load pminclock AssetBundle.");
				}
			}
			return _assetBundle;
		}

		public void BindConfigs()
		{
			ShowTime = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Show Clock", false, "Shows the actual time below the bar icon.");
			ClockStyle = ((BaseUnityPlugin)this).Config.Bind<ClockGen>("HUD", "Clock Style", ClockGen.Pikmin, "Changes the clock style.");
			IconColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "Icon Color", "(255,100,0,255)", "Color for the icon. Format the input like this (R,G,B,A)/(000,000,000,000). No letters, No Spaces.");
			DotsColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "Dots Color", "(255,0,0,255)", "Color for the dots. Format the input like this (R,G,B,A)/(000,000,000,000). No letters, No Spaces.");
			LinesColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "Lines Color", "(255,0,0,255)", "Color for the lines. Format the input like this (R,G,B,A)/(000,000,000,000). No letters, No Spaces.");
			TimeColor = ((BaseUnityPlugin)this).Config.Bind<string>("Colors", "Time Color", "(255,124,0,255)", "Color for the time. Format the input like this (R,G,B,A)/(000,000,000,000). No letters, No Spaces.");
			ShowTime.SettingChanged += delegate
			{
				if ((Object)(object)HUDManager.Instance != (Object)null)
				{
					HUDManagerPatch.SwitchClockStyle(HUDManager.Instance);
				}
			};
			IconColor.SettingChanged += delegate
			{
				HUDManagerPatch.SetColors();
			};
			DotsColor.SettingChanged += delegate
			{
				HUDManagerPatch.SetColors();
			};
			LinesColor.SettingChanged += delegate
			{
				HUDManagerPatch.SetColors();
			};
			TimeColor.SettingChanged += delegate
			{
				HUDManagerPatch.SetColors();
			};
		}

		public void BindLCConfigs()
		{
			if (IsDependencyLoaded("ainavt.lc.lethalconfig"))
			{
				LethalConfigManager.SetModDescription("Adds a Pikmin styled clock to the HUD.");
			}
		}

		public static bool IsDependencyLoaded(string pluginGUID)
		{
			return Chainloader.PluginInfos.ContainsKey(pluginGUID);
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("NoteBoxz.PikminStyledClock");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "NoteBoxz.PikminStyledClock";

		public const string PLUGIN_NAME = "LCPikminClock";

		public const string PLUGIN_VERSION = "1.1.1";
	}
}
namespace LCPikminClock.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	public class HUDManagerPatch
	{
		public static GameObject ClockInstance;

		public static GameObject ClockInstance4;

		public static Transform clockHand;

		public static Transform clockIcon;

		public static LCPikminClock.ClockGen? CurrentClockStyle;

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void StartPostfix(HUDManager __instance)
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = null;
			if ((Object)(object)LCPikminClock.ClockUI != (Object)null)
			{
				val = Object.Instantiate<GameObject>(LCPikminClock.ClockUI, ((Component)__instance.Clock.canvasGroup).gameObject.transform.Find("Container"));
			}
			GameObject clockInstance = null;
			if ((Object)(object)LCPikminClock.Clock4UI != (Object)null)
			{
				clockInstance = Object.Instantiate<GameObject>(LCPikminClock.Clock4UI, ((Component)__instance.Clock.canvasGroup).gameObject.transform.Find("Container"));
			}
			if (!((Object)(object)val == (Object)null))
			{
				__instance.clockIcon = ((Component)val.transform.Find("Icon/Image")).GetComponent<Image>();
				if (LCPikminClock.ShowTime.Value)
				{
					__instance.clockNumber = ((Component)val.transform.Find("Icon/Number")).GetComponent<TextMeshProUGUI>();
				}
				((Component)((Component)__instance.Clock.canvasGroup).gameObject.transform.Find("Container/Box")).gameObject.SetActive(false);
				((Component)__instance.shipLeavingEarlyIcon).transform.localPosition = new Vector3(18f, 183f, 33f);
				ClockInstance = val;
				ClockInstance4 = clockInstance;
				SetColors();
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void UpdatePostfix(HUDManager __instance)
		{
			if (!((Object)(object)ClockInstance4 == (Object)null) && !((Object)(object)__instance.clockIcon == (Object)null) && CurrentClockStyle != LCPikminClock.ClockStyle.Value)
			{
				SwitchClockStyle(__instance);
				CurrentClockStyle = LCPikminClock.ClockStyle.Value;
				SetColors();
			}
		}

		[HarmonyPatch("OnDisable")]
		[HarmonyPostfix]
		public static void OnDestroyPostfix(HUDManager __instance)
		{
			CurrentClockStyle = null;
		}

		public static void SwitchClockStyle(HUDManager __instance)
		{
			switch (LCPikminClock.ClockStyle.Value)
			{
			case LCPikminClock.ClockGen.Pikmin:
			{
				ClockInstance4.SetActive(false);
				ClockInstance.SetActive(true);
				__instance.clockIcon = ((Component)ClockInstance.transform.Find("Icon/Image")).GetComponent<Image>();
				GameObject gameObject2 = ((Component)ClockInstance.transform.Find("Icon/Number")).gameObject;
				if (LCPikminClock.ShowTime.Value)
				{
					__instance.clockNumber = gameObject2.GetComponent<TextMeshProUGUI>();
					gameObject2.gameObject.SetActive(true);
				}
				else
				{
					gameObject2.gameObject.SetActive(false);
				}
				break;
			}
			case LCPikminClock.ClockGen.Pikmin4:
			{
				ClockInstance.SetActive(false);
				ClockInstance4.SetActive(true);
				__instance.clockIcon = ((Component)ClockInstance4.transform.Find("Icon")).GetComponent<Image>();
				GameObject gameObject = ((Component)ClockInstance4.transform.Find("Icon/Number")).gameObject;
				if (LCPikminClock.ShowTime.Value)
				{
					__instance.clockNumber = gameObject.GetComponent<TextMeshProUGUI>();
					gameObject.gameObject.SetActive(true);
				}
				else
				{
					gameObject.gameObject.SetActive(false);
				}
				break;
			}
			}
			LCPikminClock.Logger.LogInfo((object)$"Switched Clock Style to {LCPikminClock.ClockStyle.Value}");
		}

		public static void SetColors()
		{
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ClockInstance != (Object)null)
			{
				foreach (Transform item in ClockInstance.transform.Find("Lines"))
				{
					Transform val = item;
					Image component = ((Component)val).GetComponent<Image>();
					if ((Object)(object)component != (Object)null)
					{
						((Graphic)component).color = ParseColor(LCPikminClock.LinesColor.Value);
					}
				}
				foreach (Transform item2 in ClockInstance.transform.Find("Dots"))
				{
					Transform val2 = item2;
					Image component2 = ((Component)val2).GetComponent<Image>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Graphic)component2).color = ParseColor(LCPikminClock.DotsColor.Value);
					}
				}
				Transform val3 = ClockInstance.transform.Find("Icon");
				clockIcon = val3;
				Image component3 = ((Component)ClockInstance.transform.Find("Icon/Image")).GetComponent<Image>();
				if ((Object)(object)component3 != (Object)null)
				{
					((Graphic)component3).color = ParseColor(LCPikminClock.IconColor.Value);
				}
				Image component4 = ((Component)ClockInstance.transform.Find("Icon/Circle")).GetComponent<Image>();
				if ((Object)(object)component4 != (Object)null)
				{
					((Graphic)component4).color = ParseColor(LCPikminClock.IconColor.Value);
				}
				TextMeshProUGUI component5 = ((Component)ClockInstance.transform.Find("Icon/Number")).GetComponent<TextMeshProUGUI>();
				if ((Object)(object)component5 != (Object)null)
				{
					((Graphic)component5).color = ParseColor(LCPikminClock.TimeColor.Value);
				}
			}
			if ((Object)(object)ClockInstance4 != (Object)null)
			{
				Image component6 = ((Component)ClockInstance4.transform.Find("Border")).GetComponent<Image>();
				if ((Object)(object)component6 != (Object)null)
				{
					((Graphic)component6).color = ParseColor(LCPikminClock.LinesColor.Value);
				}
				Image component7 = ((Component)ClockInstance4.transform.Find("Dots")).GetComponent<Image>();
				if ((Object)(object)component7 != (Object)null)
				{
					((Graphic)component7).color = ParseColor(LCPikminClock.DotsColor.Value);
				}
				Image component8 = ((Component)ClockInstance4.transform.Find("Icon")).GetComponent<Image>();
				if ((Object)(object)component8 != (Object)null)
				{
					((Graphic)component8).color = ParseColor(LCPikminClock.IconColor.Value);
				}
				clockHand = ClockInstance4.transform.Find("clockhand");
				Image componentInChildren = ((Component)ClockInstance4.transform.Find("clockhand")).GetComponentInChildren<Image>();
				if ((Object)(object)componentInChildren != (Object)null)
				{
					((Graphic)componentInChildren).color = ParseColor(LCPikminClock.IconColor.Value);
				}
				TextMeshProUGUI component9 = ((Component)ClockInstance4.transform.Find("Icon/Number")).GetComponent<TextMeshProUGUI>();
				if ((Object)(object)component9 != (Object)null)
				{
					((Graphic)component9).color = ParseColor(LCPikminClock.TimeColor.Value);
				}
			}
		}

		private static Color ParseColor(string colorString)
		{
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			string[] array = colorString.Trim('(', ')').Split(',');
			if (array.Length == 4 && int.TryParse(array[0], out var result) && int.TryParse(array[1], out var result2) && int.TryParse(array[2], out var result3) && int.TryParse(array[3], out var result4))
			{
				return new Color((float)result / 255f, (float)result2 / 255f, (float)result3 / 255f, (float)result4 / 255f);
			}
			LCPikminClock.Logger.LogWarning((object)("Unable to parse color config!!!: Input " + colorString + " The input should be somthing like (000,000,000,000) for (R,G,B,A)"));
			return Color.white;
		}
	}
	[HarmonyPatch(typeof(TimeOfDay))]
	public class TimeOfDayPatch
	{
		private static float startX = 371.3f;

		private static float endX = -387f;

		private static float startZ4 = -93.5f;

		private static float endZ4 = 93.5f;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void MoveDial(TimeOfDay __instance)
		{
			//IL_002e: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.currentDayTimeStarted)
			{
				float normalizedTimeOfDay = __instance.normalizedTimeOfDay;
				float x = Mathf.Lerp(startX, endX, normalizedTimeOfDay);
				Vector3 localPosition = ((Component)HUDManagerPatch.clockIcon).transform.localPosition;
				localPosition.x = x;
				((Component)HUDManagerPatch.clockIcon).transform.localPosition = localPosition;
				float z = Mathf.Lerp(startZ4, endZ4, normalizedTimeOfDay);
				Vector3 localEulerAngles = HUDManagerPatch.clockHand.localEulerAngles;
				localEulerAngles.z = z;
				HUDManagerPatch.clockHand.localEulerAngles = localEulerAngles;
			}
		}
	}
}