Decompiled source of PikminStyledClock v1.0.2

NoteBoxz.PikminStyledClock.dll

Decompiled 3 months 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;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
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.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+65f889eee0ccec9641f72c1a10dfb3cca210c4b8")]
[assembly: AssemblyProduct("LCPikminClock")]
[assembly: AssemblyTitle("NoteBoxz.PikminStyledClock")]
[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.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;
		}
	}
}
[HarmonyPatch(typeof(HUDManager))]
public class HUDManagerPatch
{
	public static GameObject ClockInstance;

	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	public static void StartPostfix(HUDManager __instance)
	{
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = null;
		if ((Object)(object)global::LCPikminClock.LCPikminClock.ClockUI != (Object)null)
		{
			val = Object.Instantiate<GameObject>(global::LCPikminClock.LCPikminClock.ClockUI, ((Component)__instance.Clock.canvasGroup).gameObject.transform.Find("Container"));
		}
		if (!((Object)(object)val == (Object)null))
		{
			__instance.clockIcon = ((Component)val.transform.Find("Icon")).GetComponent<Image>();
			if (global::LCPikminClock.LCPikminClock.ShowTime)
			{
				__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;
			SetColors();
		}
	}

	public static void SetColors()
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0172: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)ClockInstance == (Object)null)
		{
			return;
		}
		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(global::LCPikminClock.LCPikminClock.LinesColor);
			}
		}
		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(global::LCPikminClock.LCPikminClock.DotsColor);
			}
		}
		Image component3 = ((Component)ClockInstance.transform.Find("Icon")).GetComponent<Image>();
		if ((Object)(object)component3 != (Object)null)
		{
			((Graphic)component3).color = ParseColor(global::LCPikminClock.LCPikminClock.IconColor);
		}
		Image component4 = ((Component)ClockInstance.transform.Find("Icon/Circle")).GetComponent<Image>();
		if ((Object)(object)component4 != (Object)null)
		{
			((Graphic)component4).color = ParseColor(global::LCPikminClock.LCPikminClock.IconColor);
		}
		TextMeshProUGUI component5 = ((Component)ClockInstance.transform.Find("Icon/Number")).GetComponent<TextMeshProUGUI>();
		if ((Object)(object)component5 != (Object)null)
		{
			((Graphic)component5).color = ParseColor(global::LCPikminClock.LCPikminClock.TimeColor);
		}
	}

	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);
		}
		global::LCPikminClock.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 TimeOfDayPatchPatch
{
	[HarmonyPatch("Update")]
	[HarmonyPostfix]
	public static void MoveDial(TimeOfDay __instance)
	{
		//IL_0038: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		if (__instance.currentDayTimeStarted)
		{
			float num = 371.3f;
			float num2 = -387f;
			float normalizedTimeOfDay = __instance.normalizedTimeOfDay;
			float x = Mathf.Lerp(num, num2, normalizedTimeOfDay);
			Vector3 localPosition = ((Component)HUDManager.Instance.clockIcon).transform.localPosition;
			localPosition.x = x;
			((Component)HUDManager.Instance.clockIcon).transform.localPosition = localPosition;
		}
	}
}
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.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class LCPikminClock : BaseUnityPlugin
	{
		public static GameObject? ClockUI;

		public static bool ShowTime;

		public static string IconColor;

		public static string DotsColor;

		public static string LinesColor;

		public static string TimeColor;

		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();
			LoadAsset();
			if (IsDependencyLoaded("ainavt.lc.lethalconfig"))
			{
				BindLCConfigs();
			}
			else
			{
				BindConfigs();
			}
			Logger.LogInfo((object)"NoteBoxz.PikminStyledClock v1.0.0 has loaded!");
		}

		public void BindConfigs()
		{
			ConfigEntry<bool> ShowClockig = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Show Clock", false, "Shows the actual time below the bar icon.");
			ConfigEntry<string> iconColorConfig = ((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.");
			ConfigEntry<string> dotsColorConfig = ((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.");
			ConfigEntry<string> linesColorConfig = ((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.");
			ConfigEntry<string> timeColorConfig = ((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.");
			TimeColor = timeColorConfig.Value;
			LinesColor = linesColorConfig.Value;
			DotsColor = dotsColorConfig.Value;
			IconColor = iconColorConfig.Value;
			ShowTime = ShowClockig.Value;
			ShowClockig.SettingChanged += delegate
			{
				ShowTime = ShowClockig.Value;
			};
			iconColorConfig.SettingChanged += delegate
			{
				IconColor = iconColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
			dotsColorConfig.SettingChanged += delegate
			{
				DotsColor = dotsColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
			linesColorConfig.SettingChanged += delegate
			{
				LinesColor = linesColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
			timeColorConfig.SettingChanged += delegate
			{
				TimeColor = timeColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
		}

		public void BindLCConfigs()
		{
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Expected O, but got Unknown
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Expected O, but got Unknown
			//IL_01dc: 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)
			//IL_01ee: Expected O, but got Unknown
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Expected O, but got Unknown
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Expected O, but got Unknown
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Expected O, but got Unknown
			ConfigEntry<bool> ShowClockig = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD", "Show Clock", false, "Shows the actual time below the bar icon.");
			ConfigEntry<string> iconColorConfig = ((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.");
			ConfigEntry<string> dotsColorConfig = ((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.");
			ConfigEntry<string> linesColorConfig = ((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.");
			ConfigEntry<string> timeColorConfig = ((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.");
			TimeColor = timeColorConfig.Value;
			LinesColor = linesColorConfig.Value;
			DotsColor = dotsColorConfig.Value;
			IconColor = iconColorConfig.Value;
			ShowTime = ShowClockig.Value;
			ShowClockig.SettingChanged += delegate
			{
				ShowTime = ShowClockig.Value;
			};
			iconColorConfig.SettingChanged += delegate
			{
				IconColor = iconColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
			dotsColorConfig.SettingChanged += delegate
			{
				DotsColor = dotsColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
			linesColorConfig.SettingChanged += delegate
			{
				LinesColor = linesColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
			timeColorConfig.SettingChanged += delegate
			{
				TimeColor = timeColorConfig.Value;
				HUDManagerPatch.SetColors();
			};
			if (IsDependencyLoaded("ainavt.lc.lethalconfig"))
			{
				BoolCheckBoxConfigItem val = new BoolCheckBoxConfigItem(ShowClockig, new BoolCheckBoxOptions
				{
					RequiresRestart = true
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val);
				TextInputFieldConfigItem val2 = new TextInputFieldConfigItem(iconColorConfig, new TextInputFieldOptions
				{
					RequiresRestart = false
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
				TextInputFieldConfigItem val3 = new TextInputFieldConfigItem(dotsColorConfig, new TextInputFieldOptions
				{
					RequiresRestart = false
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3);
				TextInputFieldConfigItem val4 = new TextInputFieldConfigItem(linesColorConfig, new TextInputFieldOptions
				{
					RequiresRestart = false
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val4);
				TextInputFieldConfigItem val5 = new TextInputFieldConfigItem(timeColorConfig, new TextInputFieldOptions
				{
					RequiresRestart = false
				});
				LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val5);
			}
		}

		internal static void LoadAsset()
		{
			ClockUI = AssetLoader.LoadAsset<GameObject>("Assets/ClockAssets/PikminTime.prefab");
		}

		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.0.0";
	}
}