Decompiled source of ArcanumClock v1.0.1

BepInEx/plugins/ArcanumClock/ArcanumClock.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ArcanumClock")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8")]
[assembly: AssemblyVersion("1.0.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 ArcanumClock
{
	internal sealed class ClockDial
	{
		private Texture2D arc;

		private Texture2D sun;

		private Texture2D moon;

		internal void Draw(Rect bounds, double solar)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)arc))
			{
				arc = MakeTexture(256, 128, 0);
				sun = MakeTexture(64, 64, 1);
				moon = MakeTexture(64, 64, 2);
			}
			Color color = GUI.color;
			try
			{
				GUI.color = Color.white;
				GUI.DrawTexture(bounds, (Texture)(object)arc);
				float num = (float)(ClockText.DialProgress(solar) * Math.PI);
				float num2 = ((Rect)(ref bounds)).x + ((Rect)(ref bounds)).width * (0.5f - 0.4375f * Mathf.Cos(num));
				float num3 = ((Rect)(ref bounds)).y + ((Rect)(ref bounds)).height * (0.9375f - 0.875f * Mathf.Sin(num));
				float num4 = ((Rect)(ref bounds)).width * 0.1f;
				GUI.DrawTexture(new Rect(num2 - num4 / 2f, num3 - num4 / 2f, num4, num4), (Texture)(object)(ClockText.IsDay(solar) ? sun : moon));
			}
			finally
			{
				GUI.color = color;
			}
		}

		private static Texture2D MakeTexture(int width, int height, int kind)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false);
			((Object)val).name = "ArcanumClockDial";
			((Object)val).hideFlags = (HideFlags)61;
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			Color[] array = (Color[])(object)new Color[width * height];
			Color val2 = default(Color);
			for (int i = 0; i < height; i++)
			{
				for (int j = 0; j < width; j++)
				{
					float num = (float)j + 0.5f - (float)width / 2f;
					float num2 = (float)i + 0.5f - ((kind == 0) ? 8f : ((float)height / 2f));
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					if (kind == 0)
					{
						float num4 = ((num2 >= 0f) ? Mathf.Clamp01(2f - Mathf.Abs(num3 - 112f)) : 0f);
						float num5 = ((Mathf.Abs(num) <= 112f) ? (Mathf.Clamp01(1.4f - Mathf.Abs(num2)) * 0.45f) : 0f);
						float num6 = Mathf.Max(num4, num5);
						((Color)(ref val2))..ctor(0.82f, 0.77f, 0.62f, num6 * 0.8f);
					}
					else
					{
						float num6 = Mathf.Clamp01(23f - num3);
						if (kind == 2)
						{
							float num7 = Mathf.Sqrt((num - 12f) * (num - 12f) + (num2 - 7f) * (num2 - 7f));
							num6 *= Mathf.Clamp01(num7 - 21f);
						}
						val2 = ((kind == 1) ? new Color(1f, 0.78f, 0.22f, num6) : new Color(0.72f, 0.85f, 1f, num6));
					}
					array[i * width + j] = val2;
				}
			}
			val.SetPixels(array);
			val.Apply(false, true);
			return val;
		}

		internal void Dispose()
		{
			if (Object.op_Implicit((Object)(object)arc))
			{
				Object.Destroy((Object)(object)arc);
			}
			if (Object.op_Implicit((Object)(object)sun))
			{
				Object.Destroy((Object)(object)sun);
			}
			if (Object.op_Implicit((Object)(object)moon))
			{
				Object.Destroy((Object)(object)moon);
			}
		}
	}
	internal static class ClockText
	{
		internal static bool IsDay(double solar)
		{
			if (solar >= 0.25)
			{
				return solar < 0.75;
			}
			return false;
		}

		internal static double DialProgress(double solar)
		{
			if (!IsDay(solar))
			{
				return (solar + 0.25) % 1.0 * 2.0;
			}
			return (solar - 0.25) * 2.0;
		}

		internal static double ToSolarFraction(double fraction)
		{
			if (fraction >= 0.15 && fraction <= 0.85)
			{
				return 0.25 + (fraction - 0.15) / 0.7 * 0.5;
			}
			if (fraction < 0.5)
			{
				return fraction / 0.15 * 0.25;
			}
			return 0.75 + (fraction - 0.85) / 0.15 * 0.25;
		}

		internal static string Format(int day, double solarFraction)
		{
			if (double.IsNaN(solarFraction) || double.IsInfinity(solarFraction))
			{
				solarFraction = 0.0;
			}
			double num = solarFraction - Math.Floor(solarFraction);
			int num2 = Math.Min(1439, (int)(num * 1440.0));
			return string.Format(CultureInfo.InvariantCulture, "Day {0}  •  {1:00}:{2:00}", day, num2 / 60, num2 % 60);
		}
	}
	[BepInPlugin("arcanum.clock", "ArcanumClock", "1.0.1")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "arcanum.clock";

		public const string PluginName = "ArcanumClock";

		public const string PluginVersion = "1.0.1";

		private ConfigEntry<float> rightOffset;

		private ConfigEntry<float> topOffset;

		private ConfigEntry<int> fontSize;

		private ConfigEntry<bool> showDial;

		private readonly ClockDial dial = new ClockDial();

		private double solarFraction;

		private GUIStyle labelStyle;

		private readonly GUIContent content = new GUIContent();

		private bool visible;

		private float nextRefresh;

		private void Awake()
		{
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			showDial = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "ShowDial", true, "Show a sun by day and a moon at night moving left to right above the clock.");
			rightOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "RightOffset", 30f, new ConfigDescription("Distance from the right edge, in reference pixels at 1080p. Increase to move left. Restart after editing.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 4000f), Array.Empty<object>()));
			topOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "TopOffset", 270f, new ConfigDescription("Distance from the top edge, in reference pixels at 1080p. Increase to move down.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2000f), Array.Empty<object>()));
			fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Display", "FontSize", 20, new ConfigDescription("Text size at 1080p; scales with screen height.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(12, 48), Array.Empty<object>()));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ArcanumClock 1.0.1 loaded (client HUD only).");
		}

		private void Update()
		{
			Player localPlayer = Player.m_localPlayer;
			Hud instance = Hud.instance;
			EnvMan instance2 = EnvMan.instance;
			ZNet instance3 = ZNet.instance;
			visible = Object.op_Implicit((Object)(object)localPlayer) && Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance2) && Object.op_Implicit((Object)(object)instance3) && instance.IsVisible() && Object.op_Implicit((Object)(object)instance.m_rootObject) && instance.m_rootObject.activeInHierarchy && !Menu.IsVisible() && !InventoryGui.IsVisible() && !Minimap.IsOpen() && !Console.IsVisible() && !((Character)localPlayer).IsDead() && !((Character)localPlayer).IsTeleporting() && !((Character)localPlayer).InCutscene() && (!Object.op_Implicit((Object)(object)instance.m_loadingScreen) || !((Component)instance.m_loadingScreen).gameObject.activeInHierarchy || instance.m_loadingScreen.alpha <= 0.01f);
			if (!visible)
			{
				nextRefresh = 0f;
			}
			else if (!(Time.unscaledTime < nextRefresh))
			{
				nextRefresh = Time.unscaledTime + 0.2f;
				double timeSeconds = instance3.GetTimeSeconds();
				long dayLengthSec = instance2.m_dayLengthSec;
				if (dayLengthSec <= 0 || double.IsNaN(timeSeconds) || double.IsInfinity(timeSeconds))
				{
					visible = false;
					return;
				}
				double fraction = timeSeconds % (double)dayLengthSec / (double)dayLengthSec;
				solarFraction = ClockText.ToSolarFraction(fraction);
				content.text = ClockText.Format(instance2.GetDay(timeSeconds), solarFraction);
			}
		}

		private void OnGUI()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Invalid comparison between Unknown and I4
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Expected O, but got Unknown
			//IL_005e: Expected O, but got Unknown
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			if (visible && (int)Event.current.type == 7)
			{
				if (labelStyle == null)
				{
					labelStyle = new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)5,
						fontStyle = (FontStyle)1,
						wordWrap = false,
						richText = false,
						padding = new RectOffset(6, 6, 3, 3)
					};
				}
				float num = Mathf.Max(0.5f, (float)Screen.height / 1080f);
				labelStyle.fontSize = Mathf.RoundToInt((float)fontSize.Value * num);
				Vector2 val = labelStyle.CalcSize(content);
				float num2 = FiniteOffset(rightOffset.Value, 30f) * num;
				float num3 = FiniteOffset(topOffset.Value, 270f) * num;
				float num4 = 160f * num;
				float num5 = (showDial.Value ? (88f * num) : 0f);
				float num6 = Mathf.Max(val.x, showDial.Value ? num4 : 0f);
				float num7 = val.y + num5;
				float num8 = Mathf.Clamp((float)Screen.width - num2 - num6, 0f, Mathf.Max(0f, (float)Screen.width - num6));
				float num9 = Mathf.Clamp(num3, 0f, Mathf.Max(0f, (float)Screen.height - num7));
				if (showDial.Value)
				{
					dial.Draw(new Rect(num8 + (num6 - num4) / 2f, num9, num4, 80f * num), solarFraction);
				}
				Rect val3;
				Rect val2 = (val3 = new Rect(num8 + (num6 - val.x) / 2f, num9 + num5, val.x, val.y));
				((Rect)(ref val3)).position = ((Rect)(ref val3)).position + new Vector2(num, num);
				labelStyle.normal.textColor = Color.black;
				GUI.Label(val3, content, labelStyle);
				labelStyle.normal.textColor = new Color(1f, 0.9f, 0.65f, 1f);
				GUI.Label(val2, content, labelStyle);
			}
		}

		private static float FiniteOffset(float value, float fallback)
		{
			if (!float.IsNaN(value) && !float.IsInfinity(value))
			{
				return value;
			}
			return fallback;
		}

		private void OnDestroy()
		{
			dial.Dispose();
		}
	}
}