using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AccurateClockItem")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AccurateClockItem")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a949d892-aa93-45f1-816c-73b9333571bf")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AccurateClockItem;
[BepInPlugin("Swaggies.AccurateClockItem", "AccurateClockItem", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private const string _GUID = "Swaggies.AccurateClockItem";
private const string _NAME = "AccurateClockItem";
private const string _VER = "1.0.0";
private readonly Harmony harmony = new Harmony("Swaggies.AccurateClockItem");
private static Plugin Instance;
private static ManualLogSource loggacloggus;
private void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
loggacloggus = Logger.CreateLogSource("Swaggies.AccurateClockItem");
harmony.PatchAll(typeof(Plugin));
loggacloggus.LogInfo((object)"AccurateClockItem up and running.");
}
private static float ConvertFloatToRotation(float value)
{
float num = Mathf.Clamp(value * 360f, 0f, 360f);
float num2 = 360f - num + 90f;
if (num2 < 0f)
{
return 360f + num2;
}
return num2;
}
private static int Get12hHour(int h24Hour)
{
if (h24Hour % 12 == 0)
{
return 12;
}
return h24Hour % 12;
}
public static float[] GetCurrentClockWithContext()
{
DateTime now = DateTime.Now;
float num = now.Second;
float num2 = (float)now.Minute + num / 60f;
float num3 = (float)Get12hHour(now.Hour) + num2 / 60f;
if (!StartOfRound.Instance.inShipPhase && StartOfRound.Instance.currentLevel.planetHasTime)
{
float normalizedTimeOfDay = TimeOfDay.Instance.normalizedTimeOfDay;
float num4 = TimeOfDay.Instance.numberOfHours;
float num5 = normalizedTimeOfDay * (60f * num4) + 360f;
float num6 = num5 / 60f;
if (num6 >= 24f)
{
num6 = 12f;
}
else if (num6 > 12f)
{
num6 %= 12f;
}
num3 = num6;
num2 = num5 % 60f;
}
return new float[3] { num3, num2, num };
}
[HarmonyPatch(typeof(ClockProp), "Update")]
[HarmonyPostfix]
private static void UpdateClock(ref ClockProp __instance)
{
//IL_0026: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
float[] currentClockWithContext = GetCurrentClockWithContext();
__instance.secondHand.localRotation = Quaternion.Euler(ConvertFloatToRotation(currentClockWithContext[2] / 60f), 0f, 0f);
__instance.minuteHand.localRotation = Quaternion.Euler(ConvertFloatToRotation(currentClockWithContext[1] / 60f), 0f, 0f);
__instance.hourHand.localRotation = Quaternion.Euler(ConvertFloatToRotation(currentClockWithContext[0] / 12f), 0f, 0f);
}
}