using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using MycopunkShared;
using Pigeon.Movement;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MycopunkHealthRegenTimer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+fe8cef1291afd0a7f7ea8a9ddfd28d3607c4cdd5")]
[assembly: AssemblyProduct("MycopunkHealthRegenTimer")]
[assembly: AssemblyTitle("MycopunkHealthRegenTimer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.0")]
[module: UnverifiableCode]
[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 MycopunkHealthRegenTimer
{
internal static class MenuText
{
private static readonly Dictionary<string, Dictionary<string, string>> Names = new Dictionary<string, Dictionary<string, string>>
{
["en"] = new Dictionary<string, string> { ["regen.enabled"] = "Show health regeneration timer" },
["ja"] = new Dictionary<string, string> { ["regen.enabled"] = "体力回復までの時間を表示" }
};
private static readonly Dictionary<string, Dictionary<string, string>> Descriptions = new Dictionary<string, Dictionary<string, string>> { ["ja"] = new Dictionary<string, string> { ["regen.enabled"] = "体力バーの上に自動回復が始まるまでの時間を表示します。回復中や体力が満タンのときは表示しません。" } };
public static object[] Label(string key)
{
return ModsMenuTag.Label(key, (IDictionary<string, Dictionary<string, string>>)Names, (IDictionary<string, Dictionary<string, string>>)Descriptions);
}
}
[BepInPlugin("f1w3.mycopunk.healthregentimer", "Mycopunk Health Regen Timer", "0.1.2")]
[BepInDependency("doku_macaron.mycopunk.macaroncore", "1.1.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public sealed class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Player), "UpdateTarget")]
private static class UpdateTargetPatch
{
[HarmonyPrefix]
private static void Prefix(Player __instance)
{
CaptureTimer(__instance);
}
}
private const string Guid = "f1w3.mycopunk.healthregentimer";
private static Plugin _instance;
private Harmony _harmony;
private ConfigEntry<bool> _enabled;
private Player _player;
private Graphic _bar;
private TextMeshProUGUI _label;
private int _sampleFrame = -1;
private float _remaining;
private bool _captureFaulted;
private void Awake()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
_instance = this;
_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, new ConfigDescription("Show the time until health regeneration begins above your health bar.", (AcceptableValueBase)null, MenuText.Label("regen.enabled")));
_harmony = new Harmony("f1w3.mycopunk.healthregentimer");
ModsMenu.Install(_harmony, (BaseUnityPlugin)(object)this);
try
{
_harmony.CreateClassProcessor(typeof(UpdateTargetPatch)).Patch();
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Health regeneration timer unavailable: " + ex.Message));
}
}
private static void CaptureTimer(Player player)
{
//IL_0099: 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)
if ((Object)(object)_instance == (Object)null || _instance._captureFaulted || (Object)(object)player != (Object)(object)Player.LocalPlayer)
{
return;
}
_instance._sampleFrame = Time.frameCount;
_instance._remaining = 0f;
try
{
NetworkManager singleton = NetworkManager.Singleton;
if ((Object)(object)singleton == (Object)null || !singleton.IsListening || !player.IsAlive || !player.enableHealing || Time.timeScale <= 0f || player.NormalizedHealth >= player.tempMaxHealthCap || player.TempHealthRegenSpeed <= 0f)
{
return;
}
NetworkTime serverTime = singleton.ServerTime;
float timeAsFloat = ((NetworkTime)(ref serverTime)).TimeAsFloat;
if (!(timeAsFloat < player.forceHealthRegenEndTime))
{
float num = player.upgradeVariables.noDamageTimeBeforeHealthRegen * player.noDamageTimeBeforeHealthRegenMultiplier / player.TempHealthRegenSpeed - (timeAsFloat - player.LastDamageTime);
if (!float.IsNaN(num) && !float.IsInfinity(num) && num > 0f)
{
_instance._remaining = num;
}
}
}
catch (Exception ex)
{
((BaseUnityPlugin)_instance).Logger.LogWarning((object)("Health regeneration timer could not read game state: " + ex.Message));
_instance._captureFaulted = true;
_instance._sampleFrame = -1;
}
}
private void LateUpdate()
{
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
//IL_02f0: Unknown result type (might be due to invalid IL or missing references)
//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0305: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_032c: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0356: Unknown result type (might be due to invalid IL or missing references)
//IL_035b: Unknown result type (might be due to invalid IL or missing references)
//IL_0366: Expected O, but got Unknown
//IL_0373: Unknown result type (might be due to invalid IL or missing references)
//IL_037a: Unknown result type (might be due to invalid IL or missing references)
//IL_0386: Unknown result type (might be due to invalid IL or missing references)
//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
//IL_0211: Unknown result type (might be due to invalid IL or missing references)
//IL_0218: Unknown result type (might be due to invalid IL or missing references)
//IL_022a: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
Player localPlayer = Player.LocalPlayer;
if ((Object)(object)localPlayer != (Object)(object)_player)
{
if ((Object)(object)_label != (Object)null)
{
Object.Destroy((Object)(object)((Component)_label).gameObject);
}
_label = null;
_bar = null;
_player = localPlayer;
}
if ((Object)(object)localPlayer == (Object)null)
{
return;
}
if ((Object)(object)_bar == (Object)null)
{
_bar = localPlayer.healthbar;
}
if ((Object)(object)_bar == (Object)null || (Object)(object)((Transform)_bar.rectTransform).parent == (Object)null || (Object)(object)_bar.canvas == (Object)null)
{
if ((Object)(object)_label != (Object)null)
{
((Component)_label).gameObject.SetActive(false);
}
return;
}
Canvas canvas = _bar.canvas;
Canvas rootCanvas = canvas.rootCanvas;
if (!_enabled.Value || _sampleFrame != Time.frameCount || !(_remaining > 0f) || !HudVisibility.HealthBarVisible(localPlayer, _bar, canvas))
{
if ((Object)(object)_label != (Object)null)
{
((Component)_label).gameObject.SetActive(false);
}
return;
}
if ((Object)(object)_label != (Object)null && (Object)(object)((TMP_Text)_label).transform.parent != (Object)(object)((Component)rootCanvas).transform)
{
Object.Destroy((Object)(object)((Component)_label).gameObject);
_label = null;
}
if ((Object)(object)_label == (Object)null)
{
PlayerLook instance = PlayerLook.Instance;
TextMeshProUGUI val = (((Object)(object)instance != (Object)null) ? instance.PlayerTitleText : null);
if ((Object)(object)val == (Object)null)
{
return;
}
_label = GameHudText.Create(val, ((Component)rootCanvas).transform, "Health Regen Timer");
((TMP_Text)_label).alignment = (TextAlignmentOptions)1026;
((TMP_Text)_label).fontSize = 16f;
((Graphic)_label).color = Color.white;
RectTransform rectTransform = ((TMP_Text)_label).rectTransform;
Vector2 val2 = default(Vector2);
((Vector2)(ref val2))..ctor(0.5f, 0.5f);
rectTransform.anchorMax = val2;
rectTransform.anchorMin = val2;
rectTransform.pivot = new Vector2(0.5f, 0f);
((Transform)rectTransform).localRotation = Quaternion.identity;
((Transform)rectTransform).localScale = Vector3.one;
((TMP_Text)_label).transform.SetAsLastSibling();
}
if (!((Component)_label).gameObject.activeSelf)
{
((Component)_label).gameObject.SetActive(true);
}
RectTransform rectTransform2 = _bar.rectTransform;
Vector3 localScale = ((Transform)rectTransform2).localScale;
Matrix4x4 val3 = Matrix4x4.TRS(((Transform)rectTransform2).localPosition, ((Transform)rectTransform2).localRotation, new Vector3(1f, localScale.y, localScale.z));
Transform parent = ((Transform)rectTransform2).parent;
Rect rect = rectTransform2.rect;
float x = ((Rect)(ref rect)).center.x;
rect = rectTransform2.rect;
Vector3 val4 = parent.TransformPoint(((Matrix4x4)(ref val3)).MultiplyPoint3x4(new Vector3(x, ((Rect)(ref rect)).yMax, 0f)));
Camera val5 = HudCoordinates.CameraFor(rootCanvas);
if ((int)rootCanvas.renderMode != 0 && (Object)(object)val5 == (Object)null)
{
((Component)_label).gameObject.SetActive(false);
return;
}
Vector2 val6 = RectTransformUtility.WorldToScreenPoint(val5, val4);
val6.y += 5f * (float)Screen.height / 1080f;
Vector2 val7 = default(Vector2);
if (RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)((Component)rootCanvas).transform, val6, val5, ref val7))
{
((Transform)((TMP_Text)_label).rectTransform).localPosition = new Vector3(val7.x, val7.y, 0f);
}
((TMP_Text)_label).text = $"{_remaining:F1} s";
}
private void OnDestroy()
{
if ((Object)(object)_label != (Object)null)
{
Object.Destroy((Object)(object)((Component)_label).gameObject);
}
if (_harmony != null)
{
_harmony.UnpatchSelf();
}
if ((Object)(object)_instance == (Object)(object)this)
{
_instance = null;
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}