using System;
using System.Collections;
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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.chuxiaaaa.StaminaInfo")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+48a4b7493a6b412dc1b7402cb67b185f8f3b21ab")]
[assembly: AssemblyProduct("com.github.chuxiaaaa.StaminaInfo")]
[assembly: AssemblyTitle("StaminaInfo")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.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;
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace StaminaInfo
{
public static class FixPeakStatsPatches
{
private delegate void DFetchDesiredSize(object instance);
[HarmonyPatch]
private static class PatchWrapper
{
private static Type TargetType()
{
if ((object)T_CharacterStaminaBar == null)
{
T_CharacterStaminaBar = AccessTools.TypeByName("PeakStats.MonoBehaviours.CharacterStaminaBar");
}
return T_CharacterStaminaBar;
}
private static MethodBase TargetMethod()
{
Type type = TargetType();
if (type == null)
{
return null;
}
CacheFieldsAndMethods(type);
return AccessTools.Method(type, "Update", (Type[])null, (Type[])null);
}
private static void Postfix(object __instance)
{
Update(__instance);
}
}
private static Type T_CharacterStaminaBar;
private static FieldInfo F_observedCharacter;
private static FieldInfo F_characterBarAfflictions;
private static FieldInfo F_staminaBarRect;
private static FieldInfo F_fullBarRect;
private static MethodInfo M_GetInstanceID;
private static FieldInfo F_afflictionSize;
private static MethodInfo M_FetchDesiredSize;
private static FieldInfo F_afflictionGameObject;
private static DFetchDesiredSize FetchDesiredSizeDelegate;
public static Dictionary<int, float> lastUpdateTime { get; set; } = new Dictionary<int, float>();
private static void CacheFieldsAndMethods(Type t)
{
if (!(F_observedCharacter != null))
{
F_observedCharacter = AccessTools.Field(t, "observedCharacter");
F_characterBarAfflictions = AccessTools.Field(t, "characterBarAfflictions");
F_staminaBarRect = AccessTools.Field(t, "staminaBarRectTransform");
F_fullBarRect = AccessTools.Field(t, "fullBarRectTransform");
M_GetInstanceID = AccessTools.Method(t, "GetInstanceID", (Type[])null, (Type[])null);
Type type = AccessTools.TypeByName("PeakStats.MonoBehaviours.CharacterBarAffliction");
F_afflictionSize = AccessTools.Field(type, "size");
F_afflictionGameObject = AccessTools.Field(type, "gameObject");
M_FetchDesiredSize = AccessTools.Method(type, "FetchDesiredSize", (Type[])null, (Type[])null);
if (M_FetchDesiredSize != null)
{
FetchDesiredSizeDelegate = (DFetchDesiredSize)Delegate.CreateDelegate(typeof(DFetchDesiredSize), null, M_FetchDesiredSize);
}
Plugin.Log.LogInfo((object)"[StaminaInfo] PeakStats compatibility initialized with cached reflection.");
}
}
public static void Update(object instance)
{
if (instance == null)
{
return;
}
try
{
int num = (int)M_GetInstanceID.Invoke(instance, null);
if (!lastUpdateTime.ContainsKey(num))
{
lastUpdateTime[num] = -1f;
}
if (!Plugin.barTexts.ContainsKey(num + "_Stamina"))
{
InitCharacterStaminaInfo(instance, num);
}
if ((Object)(object)Character.observedCharacter != (Object)null && Time.time - lastUpdateTime[num] > 1f)
{
UpdateCharacterBarTexts(instance, num);
lastUpdateTime[num] = Time.time;
}
}
catch (Exception ex)
{
Plugin.Log.LogError((object)ex.ToString());
}
}
private static void InitCharacterStaminaInfo(object instance, int id)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
RectTransform val = (RectTransform)F_staminaBarRect.GetValue(instance);
Plugin.AddTextObjectPublic(((Component)val).gameObject, id + "_Stamina");
IEnumerable enumerable = (IEnumerable)F_characterBarAfflictions.GetValue(instance);
foreach (object item in enumerable)
{
GameObject val2 = (GameObject)F_afflictionGameObject.GetValue(item);
Plugin.AddTextObjectPublic(val2, id + "_" + ((Object)val2).name);
}
}
private static void UpdateCharacterBarTexts(object instance, int id)
{
object value = F_observedCharacter.GetValue(instance);
if (value == null)
{
return;
}
float currentStamina = GetCurrentStamina(instance, value);
string key = id + "_Stamina";
if (!Plugin.lastKnownData.ContainsKey(key) || Plugin.lastKnownData[key] != currentStamina)
{
UpdateStaminaText(key, currentStamina);
Plugin.lastKnownData[key] = currentStamina;
}
IEnumerable enumerable = (IEnumerable)F_characterBarAfflictions.GetValue(instance);
foreach (object item in enumerable)
{
UpdateAffliction(item, id);
}
}
private static float GetCurrentStamina(object instance, object observedChar)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Expected O, but got Unknown
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
float num = (float)AccessTools.Field(observedChar.GetType(), "currentStamina").GetValue(observedChar);
RectTransform val = (RectTransform)F_fullBarRect.GetValue(instance);
return Mathf.Max(0f, num * val.sizeDelta.x);
}
private static void UpdateStaminaText(string key, float v)
{
if (v >= 30f)
{
((TMP_Text)Plugin.barTexts[key]).text = (Plugin.configRoundStamina.Value ? Mathf.Round(v / 6f).ToString() : (v / 6f).ToString("F1"));
((Component)Plugin.barTexts[key]).gameObject.SetActive(true);
}
else if (v >= 15f)
{
((TMP_Text)Plugin.barTexts[key]).text = Mathf.Round(v / 6f).ToString();
((Component)Plugin.barTexts[key]).gameObject.SetActive(true);
}
else
{
((Component)Plugin.barTexts[key]).gameObject.SetActive(false);
}
}
private static void UpdateAffliction(object affliction, int id)
{
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Expected O, but got Unknown
FetchDesiredSizeDelegate(affliction);
float num = (float)F_afflictionSize.GetValue(affliction);
GameObject val = (GameObject)F_afflictionGameObject.GetValue(affliction);
string key = id + "_" + ((Object)val).name;
if (!Plugin.lastKnownData.ContainsKey(key) || Plugin.lastKnownData[key] != num)
{
TextMeshProUGUI val2 = Plugin.barTexts[key];
((TMP_Text)val2).fontSize = Plugin.configFontSize.Value;
if (num >= 30f)
{
((TMP_Text)val2).text = (Plugin.configRoundAffliction.Value ? Mathf.Round(num / 6f).ToString() : (num / 6f).ToString("F1").Replace(".0", ""));
}
else if (num >= 15f)
{
((TMP_Text)val2).text = Mathf.Round(num / 6f).ToString();
}
Plugin.lastKnownData[key] = num;
}
}
}
[BepInPlugin("com.github.chuxiaaaa.StaminaInfo", "StaminaInfo", "1.0.5")]
public class Plugin : BaseUnityPlugin
{
private static class StaminaInfoStaminaBarUpdatePatch
{
[HarmonyPatch(typeof(StaminaBar), "Update")]
[HarmonyPostfix]
private static void StaminaInfoStaminaBarUpdate(StaminaBar __instance)
{
try
{
if ((Object)(object)guiManager == (Object)null)
{
barTexts = new Dictionary<string, TextMeshProUGUI>();
lastKnownData = new Dictionary<string, float>();
lastKnownData2 = new Dictionary<string, float>();
InitStaminaInfo(__instance);
}
else if ((Object)(object)Character.observedCharacter != (Object)null)
{
UpdateBarTexts(__instance);
}
}
catch (Exception ex)
{
Log.LogError((object)(ex.Message + ex.StackTrace));
}
}
}
public static Dictionary<string, TextMeshProUGUI> barTexts;
public static Dictionary<string, float> lastKnownData;
public static Dictionary<string, float> lastKnownData2;
public static GUIManager guiManager;
public static ConfigEntry<float> configFontSize;
public static ConfigEntry<float> configOutlineWidth;
public static ConfigEntry<bool> configRoundStamina;
public static ConfigEntry<bool> configRoundAffliction;
public const string Id = "com.github.chuxiaaaa.StaminaInfo";
internal static ManualLogSource Log { get; private set; }
public static bool peakstatus { get; set; }
public static string Name => "StaminaInfo";
public static string Version => "1.0.5";
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
configFontSize = ((BaseUnityPlugin)this).Config.Bind<float>("StaminaInfo", "Font Size", 20f, "Customize the Font Size for stamina bar text.");
configOutlineWidth = ((BaseUnityPlugin)this).Config.Bind<float>("StaminaInfo", "Outline Width", 0.08f, "Customize the Outline Width for stamina bar text.");
configRoundStamina = ((BaseUnityPlugin)this).Config.Bind<bool>("StaminaInfo", "Round Stamina Bars", true, "If true, rounds to the nearest whole number for the stamina and extra stamina bars.");
configRoundAffliction = ((BaseUnityPlugin)this).Config.Bind<bool>("StaminaInfo", "Round Affliction Bars", false, "If true, rounds to the nearest whole number for affliction bars.");
Harmony.CreateAndPatchAll(typeof(StaminaInfoStaminaBarUpdatePatch), (string)null);
Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
}
private static void UpdateBarTexts(StaminaBar staminaBar)
{
//IL_034f: Unknown result type (might be due to invalid IL or missing references)
//IL_0355: Invalid comparison between Unknown and I4
//IL_0359: Unknown result type (might be due to invalid IL or missing references)
//IL_0362: Unknown result type (might be due to invalid IL or missing references)
//IL_0368: Invalid comparison between Unknown and I4
//IL_0497: Unknown result type (might be due to invalid IL or missing references)
if (lastKnownData[((Object)staminaBar.staminaBar).name] != staminaBar.desiredStaminaSize)
{
if (staminaBar.desiredStaminaSize >= 30f)
{
if (configRoundStamina.Value)
{
((TMP_Text)barTexts[((Object)staminaBar.staminaBar).name]).text = Mathf.Round(staminaBar.desiredStaminaSize / 6f).ToString();
}
else
{
((TMP_Text)barTexts[((Object)staminaBar.staminaBar).name]).text = (staminaBar.desiredStaminaSize / 6f).ToString("F1");
}
((Component)barTexts[((Object)staminaBar.staminaBar).name]).gameObject.SetActive(true);
}
else if (staminaBar.desiredStaminaSize >= 15f)
{
((TMP_Text)barTexts[((Object)staminaBar.staminaBar).name]).text = Mathf.Round(staminaBar.desiredStaminaSize / 6f).ToString();
((Component)barTexts[((Object)staminaBar.staminaBar).name]).gameObject.SetActive(true);
}
else
{
((Component)barTexts[((Object)staminaBar.staminaBar).name]).gameObject.SetActive(false);
}
lastKnownData[((Object)staminaBar.staminaBar).name] = staminaBar.desiredStaminaSize;
}
if (lastKnownData["ExtraStamina"] != staminaBar.desiredExtraStaminaSize)
{
if (staminaBar.desiredExtraStaminaSize >= 30f)
{
if (configRoundStamina.Value)
{
((TMP_Text)barTexts["ExtraStamina"]).text = Mathf.Round(staminaBar.desiredExtraStaminaSize / 6f).ToString();
}
else
{
((TMP_Text)barTexts["ExtraStamina"]).text = (staminaBar.desiredExtraStaminaSize / 6f).ToString("F1");
}
((Component)barTexts["ExtraStamina"]).gameObject.SetActive(true);
}
else if (staminaBar.desiredExtraStaminaSize >= 15f)
{
((TMP_Text)barTexts["ExtraStamina"]).text = Mathf.Round(staminaBar.desiredExtraStaminaSize / 6f).ToString();
((Component)barTexts["ExtraStamina"]).gameObject.SetActive(true);
}
else
{
((Component)barTexts["ExtraStamina"]).gameObject.SetActive(false);
}
lastKnownData["ExtraStamina"] = staminaBar.desiredExtraStaminaSize;
}
BarAffliction[] afflictions = staminaBar.afflictions;
foreach (BarAffliction val in afflictions)
{
if (!(Time.time - lastKnownData[((Object)val).name] > 0.5f) || !(val.size > 0f))
{
continue;
}
bool flag = (int)val.afflictionType != 7 && (int)val.afflictionType != 0 && (int)val.afflictionType != 5;
if (lastKnownData[((Object)val).name] != val.size || flag)
{
if (val.size >= 30f)
{
if (configRoundAffliction.Value)
{
((TMP_Text)barTexts[((Object)val).name]).text = Mathf.Round(val.size / 6f).ToString();
}
else
{
((TMP_Text)barTexts[((Object)val).name]).text = (val.size / 6f).ToString("F1").Replace(".0", "");
}
}
else if (val.size >= 15f)
{
((TMP_Text)barTexts[((Object)val).name]).text = Mathf.Round(val.size / 6f).ToString();
}
}
if (flag)
{
float reductionTimeRemaining = GetReductionTimeRemaining(val.afflictionType);
if (reductionTimeRemaining != 0f)
{
TextMeshProUGUI obj = barTexts[((Object)val).name];
((TMP_Text)obj).text = ((TMP_Text)obj).text + "(" + FormatTime(reductionTimeRemaining) + ")";
}
}
lastKnownData2[((Object)val).name] = val.size;
lastKnownData[((Object)val).name] = Time.time;
}
}
private static float GetReductionTimeRemaining(STATUSTYPE statusType)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Invalid comparison between Unknown and I4
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
//IL_0120: Unknown result type (might be due to invalid IL or missing references)
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
CharacterAfflictions val = Character.observedCharacter?.refs?.afflictions;
if ((Object)(object)val == (Object)null)
{
return 0f;
}
if ((int)statusType == 9)
{
float num = 0f;
int num2 = 0;
foreach (ThornOnMe physicalThorn in val.physicalThorns)
{
if (physicalThorn.stuckIn)
{
num2++;
num += Time.time - physicalThorn.popOutTime;
}
}
if (num2 == 0)
{
return 0f;
}
return Mathf.Abs(num) / (float)num2;
}
float currentStatus = val.GetCurrentStatus(statusType);
if (currentStatus <= 0f)
{
return 0f;
}
float reductionRate = GetReductionRate(val, statusType);
if (reductionRate <= 0f)
{
return 0f;
}
float cooldown = GetCooldown(val, statusType);
float num3 = val.LastAddedStatus(statusType);
float time = Time.time;
if (cooldown > 0f && time - num3 < cooldown)
{
float num4 = cooldown - (time - num3);
float num5 = currentStatus / reductionRate;
return num4 + num5;
}
return currentStatus / reductionRate;
}
private static float GetReductionRate(CharacterAfflictions afflictions, STATUSTYPE statusType)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected I4, but got Unknown
if ((int)statusType != 3)
{
return (statusType - 6) switch
{
2 => afflictions.hotReductionPerSecond,
4 => afflictions.sporesReductionPerSecond,
0 => afflictions.drowsyReductionPerSecond,
_ => 0f,
};
}
return afflictions.poisonReductionPerSecond;
}
private static float GetCooldown(CharacterAfflictions afflictions, STATUSTYPE statusType)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Invalid comparison between Unknown and I4
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Expected I4, but got Unknown
if ((int)statusType != 3)
{
return (statusType - 6) switch
{
2 => afflictions.hotReductionCooldown,
4 => afflictions.sporesReductionCooldown,
0 => afflictions.drowsyReductionCooldown,
_ => 0f,
};
}
return afflictions.poisonReductionCooldown;
}
private static string FormatTime(float seconds)
{
if (seconds < 60f)
{
return Mathf.CeilToInt(seconds).ToString();
}
if (seconds < 3600f)
{
int num = Mathf.FloorToInt(seconds / 60f);
int num2 = Mathf.CeilToInt(seconds % 60f);
return $"{num}:{num2:D2}";
}
int num3 = Mathf.FloorToInt(seconds / 3600f);
int num4 = Mathf.FloorToInt(seconds % 3600f / 60f);
return $"{num3}:{num4:D2}";
}
private static void InitStaminaInfo(StaminaBar staminaBar)
{
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b4: Expected O, but got Unknown
GameObject val = GameObject.Find("GAME/GUIManager");
guiManager = val.GetComponent<GUIManager>();
AddTextObjectPublic(((Component)staminaBar.staminaBar).gameObject, ((Object)staminaBar.staminaBar).name);
AddTextObjectPublic(((Component)staminaBar.extraBarStamina).gameObject, "ExtraStamina");
BarAffliction[] afflictions = staminaBar.afflictions;
foreach (BarAffliction val2 in afflictions)
{
AddTextObjectPublic(((Component)val2).gameObject, ((Object)((Component)val2).gameObject).name);
}
if (!peakstatus)
{
peakstatus = true;
if (Chainloader.PluginInfos.ContainsKey("nickklmao.peakstats"))
{
Harmony val3 = new Harmony("com.github.chuxiaaaa.StaminaInfo");
Type type = Type.GetType("StaminaInfo.FixPeakStatsPatches, com.github.chuxiaaaa.StaminaInfo");
val3.PatchAll(type);
}
}
}
private static void AddTextObject(GameObject gameObj, string barName)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
TMP_FontAsset font = ((TMP_Text)guiManager.heroDayText).font;
GameObject val = new GameObject("StaminaInfo");
val.transform.SetParent(gameObj.transform);
TextMeshProUGUI val2 = val.AddComponent<TextMeshProUGUI>();
RectTransform component = val.GetComponent<RectTransform>();
gameObj.SetActive(true);
((TMP_Text)val2).font = font;
((TMP_Text)val2).fontSize = configFontSize.Value;
component.offsetMin = new Vector2(0f, 0f);
component.offsetMax = new Vector2(0f, 0f);
((TMP_Text)val2).alignment = (TextAlignmentOptions)514;
((TMP_Text)val2).verticalAlignment = (VerticalAlignmentOptions)8192;
((TMP_Text)val2).textWrappingMode = (TextWrappingModes)0;
((TMP_Text)val2).text = "";
((TMP_Text)val2).transform.localScale = new Vector3(1f, 1f, 1f);
barTexts.Add(barName, val2);
lastKnownData.Add(barName, 0f);
((TMP_Text)val2).outlineWidth = configOutlineWidth.Value;
}
public static void AddTextObjectPublic(GameObject gameObj, string barName)
{
AddTextObject(gameObj, barName);
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}