using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("TimeDisplay")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TimeDisplay")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e22d9bce-728e-4f4e-985b-29b57c20f308")]
[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")]
[BepInPlugin("TimeDisplay", "Time Display", "1.0.0")]
public class MoneyTimeTavernDisplay : BaseUnityPlugin
{
[HarmonyPatch(typeof(PlayerUI), "Start")]
private static class PlayerUI_Start_Patch
{
private static void Postfix(PlayerUI __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
FieldInfo fieldInfo = AccessTools.Field(typeof(PlayerUI), "moneyText");
TextMeshProUGUI val = (TextMeshProUGUI)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null);
if (!((Object)(object)val == (Object)null))
{
MoneyTimeTavernOverlay moneyTimeTavernOverlay = ((Component)__instance).GetComponent<MoneyTimeTavernOverlay>();
if ((Object)(object)moneyTimeTavernOverlay == (Object)null)
{
moneyTimeTavernOverlay = ((Component)__instance).gameObject.AddComponent<MoneyTimeTavernOverlay>();
}
moneyTimeTavernOverlay.Init(val);
}
}
}
private sealed class MoneyTimeTavernOverlay : MonoBehaviour
{
private TextMeshProUGUI _moneyText;
private RectTransform _moneyRT;
private TextMeshProUGUI _extraText;
private RectTransform _extraRT;
private float _nextUpdateTime;
private string _lastRendered;
private float _lastMoneyPreferredWidth;
private const float UpdateInterval = 0.2f;
private const float PaddingX = 18f;
public void Init(TextMeshProUGUI moneyText)
{
_moneyText = moneyText;
_moneyRT = (((Object)(object)moneyText != (Object)null) ? ((TMP_Text)moneyText).rectTransform : null);
if (!((Object)(object)_moneyText == (Object)null) && !((Object)(object)_moneyRT == (Object)null))
{
EnsureExtraText();
ForceUpdate();
}
}
private void EnsureExtraText()
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002d: Expected O, but got Unknown
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_0126: Unknown result type (might be due to invalid IL or missing references)
//IL_013c: Unknown result type (might be due to invalid IL or missing references)
//IL_017f: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)_extraText != (Object)null))
{
GameObject val = new GameObject("MoneyTimeTavernText", new Type[1] { typeof(RectTransform) });
val.layer = ((Component)_moneyText).gameObject.layer;
_extraRT = val.GetComponent<RectTransform>();
((Transform)_extraRT).SetParent(((Transform)_moneyRT).parent, false);
_extraRT.anchorMin = _moneyRT.anchorMin;
_extraRT.anchorMax = _moneyRT.anchorMax;
_extraRT.pivot = _moneyRT.pivot;
_extraRT.anchoredPosition = _moneyRT.anchoredPosition + new Vector2(18f, 0f);
((Transform)_extraRT).localScale = Vector3.one;
_extraText = val.AddComponent<TextMeshProUGUI>();
((TMP_Text)_extraText).font = ((TMP_Text)_moneyText).font;
((TMP_Text)_extraText).fontSize = ((TMP_Text)_moneyText).fontSize;
((TMP_Text)_extraText).fontStyle = ((TMP_Text)_moneyText).fontStyle;
((Graphic)_extraText).color = ((Graphic)_moneyText).color;
((TMP_Text)_extraText).alignment = (TextAlignmentOptions)513;
((Graphic)_extraText).raycastTarget = false;
((TMP_Text)_extraText).enableWordWrapping = false;
_extraRT.sizeDelta = new Vector2(500f, _moneyRT.sizeDelta.y);
}
}
private void Update()
{
if (!((Object)(object)_moneyText == (Object)null) && !((Object)(object)_moneyRT == (Object)null) && !((Object)(object)_extraText == (Object)null) && !((Object)(object)_extraRT == (Object)null) && !(Time.unscaledTime < _nextUpdateTime))
{
_nextUpdateTime = Time.unscaledTime + 0.2f;
RenderIfChanged();
}
}
private void ForceUpdate()
{
_lastRendered = null;
_lastMoneyPreferredWidth = -1f;
RenderIfChanged();
}
private void RenderIfChanged()
{
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)DayNight.Instance == (Object)null || (Object)(object)GameStatus.Instance == (Object)null)
{
if (!string.IsNullOrEmpty(((TMP_Text)_extraText).text))
{
((TMP_Text)_extraText).text = "";
}
return;
}
int value = DayNight.Instance.hours.Value;
int minutes = DayNight.Instance.minutes;
string arg = (GameStatus.Instance.isTavernOpen.Value ? "Open" : "Closed");
string text = $"{value:00}:{minutes:00} Tavern : {arg}";
if (!string.Equals(_lastRendered, text, StringComparison.Ordinal))
{
((TMP_Text)_extraText).text = text;
_lastRendered = text;
}
float preferredWidth = ((TMP_Text)_moneyText).preferredWidth;
if (Math.Abs(preferredWidth - _lastMoneyPreferredWidth) > 0.1f)
{
_lastMoneyPreferredWidth = preferredWidth;
_extraRT.anchoredPosition = _moneyRT.anchoredPosition + new Vector2(preferredWidth + 18f, 0f);
}
}
}
public const string PluginGuid = "TimeDisplay";
public const string PluginName = "Time Display";
public const string PluginVersion = "1.0.0";
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("TimeDisplay").PatchAll(typeof(MoneyTimeTavernDisplay).Assembly);
}
}