using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using PlayerHUDTweaks.Patches;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("PlayerHUDTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PlayerHUDTweaks")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("786ce4ce-e0f6-4ba3-be03-44163230cd29")]
[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 PlayerHUDTweaks
{
internal class BatteryNumber
{
private static TextMeshProUGUI batteryNumber = null;
private static Vector3 basePosition = Vector3.zero;
private static readonly Color batteryColor = new Color(1f, 1f, 0.191f);
private static readonly Color outOfBatteryColor = new Color(0.3f, 0.3f, 0.3f, 0.9f);
public static void Start()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)batteryNumber != (Object)null))
{
batteryNumber = Object.Instantiate<TextMeshProUGUI>(HUDManager.Instance.weightCounter);
((TMP_Text)batteryNumber).transform.SetParent(((Component)WeightCounter.phtUI).transform, false);
((TMP_Text)batteryNumber).transform.position = ((TMP_Text)HUDManager.Instance.weightCounter).transform.position;
((TMP_Text)batteryNumber).transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
Transform transform = ((TMP_Text)batteryNumber).transform;
transform.localPosition += new Vector3(-87f, 146f);
((TMP_Text)batteryNumber).transform.localEulerAngles = new Vector3(0f, 0f, 20f);
((TMP_Text)batteryNumber).alignment = (TextAlignmentOptions)257;
((TMP_Text)batteryNumber).margin = new Vector4(0f, 0f, 0f, 0f);
((TMP_Text)batteryNumber).lineSpacing = -10f;
((TMP_Text)batteryNumber).fontSize = 15f;
((Object)batteryNumber).name = "PHTBatteryNumber";
((Graphic)batteryNumber).color = batteryColor;
((TMP_Text)batteryNumber).text = "100%";
((TMP_Text)batteryNumber).alpha = 0f;
basePosition = ((TMP_Text)batteryNumber).transform.localPosition;
}
}
public static void Update()
{
//IL_0096: Unknown result type (might be due to invalid IL or missing references)
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.BN_enabled.Value || (Object)(object)HUDManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
{
((TMP_Text)batteryNumber).alpha = 0f;
return;
}
int currentBatteryPercentage = GetCurrentBatteryPercentage();
if (currentBatteryPercentage == -1)
{
((TMP_Text)batteryNumber).alpha = 0f;
return;
}
SetBaseBatteryConfiguration();
((TMP_Text)batteryNumber).text = $"{currentBatteryPercentage}%";
((Graphic)batteryNumber).color = ((currentBatteryPercentage > 0) ? batteryColor : outOfBatteryColor);
}
private static void SetBaseBatteryConfiguration()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
((TMP_Text)batteryNumber).alpha = 1f;
((TMP_Text)batteryNumber).transform.localPosition = basePosition + new Vector3(Plugin.BN_xOffset.Value, Plugin.BN_yOffset.Value);
((TMP_Text)batteryNumber).font = (Plugin.BN_textShadow.Value ? ((TMP_Text)HUDManager.Instance.planetRiskLevelText).font : ((TMP_Text)HUDManager.Instance.totalValueText).font);
((TMP_Text)batteryNumber).fontSize = Plugin.BN_fontSize.Value;
}
private static int GetCurrentBatteryPercentage()
{
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
GrabbableObject currentlyHeldObjectServer = localPlayerController.currentlyHeldObjectServer;
if (localPlayerController.isHoldingObject && (Object)(object)currentlyHeldObjectServer != (Object)null && currentlyHeldObjectServer.itemProperties.requiresBattery)
{
return Mathf.Clamp((int)Math.Ceiling(100f * currentlyHeldObjectServer.insertedBattery.charge), 0, 9999);
}
if (((Behaviour)localPlayerController.helmetLight).enabled)
{
return Mathf.Clamp((int)Math.Ceiling(100f * localPlayerController.pocketedFlashlight.insertedBattery.charge), 0, 9999);
}
return -1;
}
}
internal class Config
{
}
internal class HealthImage
{
private static Image healthImage;
public static void Start()
{
if (!Plugin.HI_enable.Value)
{
healthImage = null;
return;
}
healthImage = ((Component)HUDManager.Instance.selfRedCanvasGroup).GetComponent<Image>();
HUDManager.Instance.selfRedCanvasGroup.alpha = 1f;
healthImage.type = (Type)3;
healthImage.fillAmount = 0f;
healthImage.fillMethod = (FillMethod)1;
healthImage.fillOrigin = 0;
}
public static void OnHealthChange(int health)
{
if (!((Object)(object)healthImage == (Object)null) && !((Object)(object)HUDManager.Instance == (Object)null))
{
if (!Plugin.HI_shouldFade.Value)
{
HUDManager.Instance.selfRedCanvasGroup.alpha = 1f;
}
healthImage.fillAmount = 1f - Mathf.InverseLerp((float)Plugin.HI_minHealth.Value, (float)Plugin.HI_maxHealth.Value, (float)health);
}
}
}
internal class HealthNumber
{
private static TextMeshProUGUI healthNumber = null;
private static Color healthColor = new Color(1f, 1f, 1f);
private static Vector3 basePosition = Vector3.zero;
public static void Start()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0168: Unknown result type (might be due to invalid IL or missing references)
//IL_016d: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)healthNumber != (Object)null))
{
healthNumber = Object.Instantiate<TextMeshProUGUI>(HUDManager.Instance.weightCounter);
((TMP_Text)healthNumber).transform.SetParent(((Component)WeightCounter.phtUI).transform, false);
((TMP_Text)healthNumber).transform.position = ((TMP_Text)HUDManager.Instance.weightCounter).transform.position;
((TMP_Text)healthNumber).transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
Transform transform = ((TMP_Text)healthNumber).transform;
transform.localPosition += new Vector3(-200f, 43f);
((TMP_Text)healthNumber).alignment = (TextAlignmentOptions)260;
((TMP_Text)healthNumber).margin = new Vector4(0f, 0f, 0f, 0f);
((TMP_Text)healthNumber).lineSpacing = -10f;
((TMP_Text)healthNumber).fontSize = 12f;
((Object)healthNumber).name = "PHTHealthNumber";
((Graphic)healthNumber).color = new Color(1f, 1f, 1f);
((TMP_Text)healthNumber).text = "100 HP";
((TMP_Text)healthNumber).alpha = 0f;
basePosition = ((TMP_Text)healthNumber).transform.localPosition;
}
}
public static void Update()
{
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_0137: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.HN_enabled.Value || (Object)(object)HUDManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
{
((TMP_Text)healthNumber).alpha = 0f;
return;
}
SetBaseHealthConfiguration();
int num = Mathf.Clamp((!GameNetworkManager.Instance.localPlayerController.isPlayerDead) ? GameNetworkManager.Instance.localPlayerController.health : 0, 0, 999);
((TMP_Text)healthNumber).text = $"{num} HP";
healthColor = Color.Lerp(new Color(1f, 0f, 0f), new Color(1f, 1f, 1f), Mathf.InverseLerp((float)Plugin.HN_minHealth.Value, (float)Plugin.HN_maxHealth.Value, (float)num));
if (num <= 0)
{
healthColor = new Color(0.3f, 0.3f, 0.3f);
}
if (GameNetworkManager.Instance.localPlayerController.criticallyInjured)
{
((Graphic)healthNumber).color = Color.Lerp(healthColor, new Color(1f, 1f, 1f), 1f - Math.Abs(2f * (Time.realtimeSinceStartup % 1f - 0.5f)));
}
else
{
((Graphic)healthNumber).color = healthColor;
}
}
private static void SetBaseHealthConfiguration()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
((TMP_Text)healthNumber).alpha = 1f;
((TMP_Text)healthNumber).transform.localPosition = basePosition + new Vector3(Plugin.HN_xOffset.Value, Plugin.HN_yOffset.Value);
((TMP_Text)healthNumber).font = (Plugin.HN_textShadow.Value ? ((TMP_Text)HUDManager.Instance.planetRiskLevelText).font : ((TMP_Text)HUDManager.Instance.totalValueText).font);
}
}
[BepInPlugin("Swaggies.PlayerHUDTweaks", "PlayerHUDTweaks", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
public enum RoundingOptions
{
Floor,
Round,
Ceiling
}
public enum DisplayMetric
{
Pounds,
Kilograms,
Grams
}
public enum MetricDisplayType
{
Default,
Abbreviated,
Full
}
public const string _guid = "Swaggies.PlayerHUDTweaks";
public const string _name = "PlayerHUDTweaks";
public const string _ver = "1.1.0";
public static Plugin Instance;
private static Harmony harmony;
private static ManualLogSource loggerwogger;
public static ConfigEntry<bool> BN_enabled;
public static ConfigEntry<bool> BN_textShadow;
public static ConfigEntry<int> BN_fontSize;
public static ConfigEntry<float> BN_xOffset;
public static ConfigEntry<float> BN_yOffset;
public static ConfigEntry<bool> SN_enabled;
public static ConfigEntry<bool> SN_textShadow;
public static ConfigEntry<float> SN_xOffset;
public static ConfigEntry<float> SN_yOffset;
public static ConfigEntry<bool> HN_enabled;
public static ConfigEntry<bool> HN_flashInCrit;
public static ConfigEntry<bool> HN_textShadow;
public static ConfigEntry<int> HN_minHealth;
public static ConfigEntry<int> HN_maxHealth;
public static ConfigEntry<float> HN_xOffset;
public static ConfigEntry<float> HN_yOffset;
public static ConfigEntry<int> HI_minHealth;
public static ConfigEntry<int> HI_maxHealth;
public static ConfigEntry<bool> HI_shouldFade;
public static ConfigEntry<bool> HI_updateEveryFrame;
public static ConfigEntry<bool> HI_enable;
public static ConfigEntry<float> SM_minStamina;
public static ConfigEntry<float> SM_maxStamina;
public static ConfigEntry<bool> SM_enableTweaks;
public static ConfigEntry<bool> SM_fadeToRed;
public static ConfigEntry<bool> WC_enableTweaks;
public static ConfigEntry<RoundingOptions> WC_weightDisplayRounding;
public static ConfigEntry<DisplayMetric> WC_metric;
public static ConfigEntry<MetricDisplayType> WC_metricDisplayType;
public static ConfigEntry<bool> WC_showDecimal;
public static ConfigEntry<bool> WC_betterFontType;
public static ConfigEntry<bool> WC_customFormatting;
public static ConfigEntry<float> WC_countupTime;
public static ConfigEntry<float> WC_countdownTime;
private void Awake()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
harmony = new Harmony("Swaggies.PlayerHUDTweaks");
loggerwogger = Logger.CreateLogSource("Swaggies.PlayerHUDTweaks");
loggerwogger.LogInfo((object)"PlayerHUDTweaks up and running.");
harmony.PatchAll(typeof(Plugin));
harmony.PatchAll(typeof(HUDManagerPatch));
harmony.PatchAll(typeof(PlayerControllerBPatch));
CreateConfig();
}
private void CreateConfig()
{
CreateHealthImageConfig();
CreateStaminaMeterConfig();
CreateWeightCounterConfig();
CreateHealthNumberConfig();
CreateStaminaNumberConfig();
CreateBatteryNumberConfig();
}
private void CreateBatteryNumberConfig()
{
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_006f: Expected O, but got Unknown
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Expected O, but got Unknown
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Expected O, but got Unknown
BN_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Battery Number", "Enabled", false, "Display your held item's battery percentage as a number next to the battery icon at the top left");
BN_textShadow = ((BaseUnityPlugin)this).Config.Bind<bool>("Battery Number", "Text Shadow", false, "If the battery number should use the in-game font with a text shadow");
BN_fontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Battery Number", "Font Size", 15, new ConfigDescription("Resize the battery number (may require repositioning)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(8, 24), Array.Empty<object>()));
BN_xOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Battery Number", "X Offset", 0f, new ConfigDescription("Reposition the battery number (left/right).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-250f, 250f), Array.Empty<object>()));
BN_yOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Battery Number", "Y Offset", 0f, new ConfigDescription("Reposition the battery number (up/down).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-200f, 200f), Array.Empty<object>()));
}
private void CreateStaminaNumberConfig()
{
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
SN_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Stamina Number", "Enabled", false, "Display your current stamina percentage as a number next to your player model outline");
SN_textShadow = ((BaseUnityPlugin)this).Config.Bind<bool>("Stamina Number", "Text Shadow", false, "If the stamina number should use the in-game font with a text shadow");
SN_xOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina Number", "X Offset", 0f, new ConfigDescription("Reposition the stamina number (left/right).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-250f, 250f), Array.Empty<object>()));
SN_yOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina Number", "Y Offset", 0f, new ConfigDescription("Reposition the stamina number (up/down).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-200f, 200f), Array.Empty<object>()));
}
private void CreateHealthNumberConfig()
{
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Expected O, but got Unknown
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Expected O, but got Unknown
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Expected O, but got Unknown
HN_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Health Number", "Enabled", false, "Display your current health as a number next to your player model outline");
HN_flashInCrit = ((BaseUnityPlugin)this).Config.Bind<bool>("Health Number", "Flash During Critical Injury", true, "If the health number should flash white while you're critically injured");
HN_textShadow = ((BaseUnityPlugin)this).Config.Bind<bool>("Health Number", "Text Shadow", false, "If the health number should use the in-game font with a text shadow");
HN_minHealth = ((BaseUnityPlugin)this).Config.Bind<int>("Health Number", "Minimum Health", 0, new ConfigDescription("At which health should the number be fully red", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>()));
HN_maxHealth = ((BaseUnityPlugin)this).Config.Bind<int>("Health Number", "Maximum Health", 100, new ConfigDescription("At which health should the number be fully white", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 200), Array.Empty<object>()));
HN_xOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Health Number", "X Offset", 0f, new ConfigDescription("Reposition the health number (left/right).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-250f, 250f), Array.Empty<object>()));
HN_yOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Health Number", "Y Offset", 0f, new ConfigDescription("Reposition the health number (up/down).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(-200f, 200f), Array.Empty<object>()));
}
private void CreateHealthImageConfig()
{
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00c5: Expected O, but got Unknown
HI_enable = ((BaseUnityPlugin)this).Config.Bind<bool>("Health Image Dynamic Fill", "Enabled", true, "Should the player model outline dynamically fill up with how much health you have (requires lobby rejoin)");
HI_shouldFade = ((BaseUnityPlugin)this).Config.Bind<bool>("Health Image Dynamic Fill", "Affect Transparency Too", false, "Should the transparency of the red image change like it does in vanilla (if not, will always be 100% opaque)");
HI_updateEveryFrame = ((BaseUnityPlugin)this).Config.Bind<bool>("Health Image Dynamic Fill", "Update Every Frame", false, "If the health UI should be updated every frame. If disabled, the UI will be updated when you take damage. Enable if some mods change your player's health without also updating the UI.");
HI_minHealth = ((BaseUnityPlugin)this).Config.Bind<int>("Health Image Dynamic Fill", "Minimum Health", 0, new ConfigDescription("At this health the player model outline will be completely red", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>()));
HI_maxHealth = ((BaseUnityPlugin)this).Config.Bind<int>("Health Image Dynamic Fill", "Maximum Health", 100, new ConfigDescription("At this health the player model outline will be completely empty", (AcceptableValueBase)(object)new AcceptableValueRange<int>(20, 200), Array.Empty<object>()));
}
private void CreateStaminaMeterConfig()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_008c: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
SM_enableTweaks = ((BaseUnityPlugin)this).Config.Bind<bool>("Stamina Meter Tweaks", "Enabled", true, "If enabled, the stamina meter will be adjusted so that it is fully depleted when below the configured Minimum Stamina amount and full when above Maximum Stamina (requires lobby rejoin)");
SM_minStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina Meter Tweaks", "Minimum Stamina", 0.1f, new ConfigDescription("Stamina threshold for when the meter should be fully depleted", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.3f), Array.Empty<object>()));
SM_maxStamina = ((BaseUnityPlugin)this).Config.Bind<float>("Stamina Meter Tweaks", "Maximum Stamina", 1f, new ConfigDescription("Stamina threshold for when the meter should be visually full", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 1f), Array.Empty<object>()));
SM_fadeToRed = ((BaseUnityPlugin)this).Config.Bind<bool>("Stamina Meter Tweaks", "Turn Red When Exhausted", true, "Make the stamina meter turn red when the player is exhausted");
}
private void CreateWeightCounterConfig()
{
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0119: Expected O, but got Unknown
//IL_014c: Unknown result type (might be due to invalid IL or missing references)
//IL_0156: Expected O, but got Unknown
WC_enableTweaks = ((BaseUnityPlugin)this).Config.Bind<bool>("Weight Counter Tweaks", "Enabled", true, "Enable all of the weight counter tweaks that are customizable in this section. Disable for vanilla weight counter behaviour (requires lobby rejoin)");
WC_betterFontType = ((BaseUnityPlugin)this).Config.Bind<bool>("Weight Counter Tweaks", "Text Shadow", false, "If enabled, swaps the font of the weight counter to the one with a text shadow for better readability");
WC_customFormatting = ((BaseUnityPlugin)this).Config.Bind<bool>("Weight Counter Tweaks", "Revamped Formatting", true, "If enabled, the weight counter will have a much more diverse color set and font size as weight gets higher. Disable for vanilla behaviour on colors and size");
WC_showDecimal = ((BaseUnityPlugin)this).Config.Bind<bool>("Weight Counter Tweaks", "Show Decimal", false, "If enabled, the weight counter will be displayed to one decimal place");
WC_metric = ((BaseUnityPlugin)this).Config.Bind<DisplayMetric>("Weight Counter Tweaks", "Weight Unit", DisplayMetric.Pounds, "Which unit to use when displaying weight");
WC_metricDisplayType = ((BaseUnityPlugin)this).Config.Bind<MetricDisplayType>("Weight Counter Tweaks", "Unit Display Type", MetricDisplayType.Default, "Change how the unit is displayed on the counter.\nDefault: [ lb / kg / g ]\nAbbreviated: [ lb. / kg. / g. ]\nFull: [ pounds / kilograms / grams ]");
WC_weightDisplayRounding = ((BaseUnityPlugin)this).Config.Bind<RoundingOptions>("Weight Counter Tweaks", "Number Rounding", RoundingOptions.Round, "How the counter should be rounded. Floor will round down, Ceiling will round up.");
WC_countupTime = ((BaseUnityPlugin)this).Config.Bind<float>("Weight Counter Tweaks", "Count-up Time", 0f, new ConfigDescription("Time in seconds for the weight counter to reach your current weight from the previous when picking up an object. Set to zero for an instant update.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
WC_countdownTime = ((BaseUnityPlugin)this).Config.Bind<float>("Weight Counter Tweaks", "Count-down Time", 0f, new ConfigDescription("Time in seconds for the weight counter to reach your current weight from the previous when dropping an object. Set to zero for an instant update.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 2f), Array.Empty<object>()));
}
}
internal class StaminaMeter
{
private static Image staminaMeter = null;
public static float staminaColorTransitionTime = 0f;
private static readonly float staminaMeterVisualMin = 0.297f;
private static readonly float staminaMeterVisualMax = 0.909f;
public static readonly Color colorNotExhausted = new Color(1f, 0.4626f, 0f);
public static readonly Color colorExhausted = new Color(1f, 0f, 0f);
public static void Start()
{
if (!Plugin.SM_enableTweaks.Value)
{
staminaMeter = null;
}
else
{
staminaMeter = GameNetworkManager.Instance.localPlayerController.sprintMeterUI;
}
}
public static void Update(float meter)
{
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)staminaMeter == (Object)null))
{
float num = Mathf.InverseLerp(Plugin.SM_minStamina.Value, Plugin.SM_maxStamina.Value, meter);
staminaMeter.fillAmount = Mathf.Lerp(staminaMeterVisualMin, staminaMeterVisualMax, num);
if (Plugin.SM_fadeToRed.Value)
{
float num2 = ((meter <= 0.3f) ? 1f : 0f);
staminaColorTransitionTime = Mathf.MoveTowards(staminaColorTransitionTime, num2, Time.deltaTime * 2.5f);
((Graphic)staminaMeter).color = Color.Lerp(colorNotExhausted, colorExhausted, staminaColorTransitionTime);
}
}
}
}
internal class StaminaNumber
{
private static TextMeshProUGUI staminaNumber = null;
private static Vector3 basePosition = Vector3.zero;
public static void Start()
{
//IL_005d: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)staminaNumber != (Object)null))
{
staminaNumber = Object.Instantiate<TextMeshProUGUI>(HUDManager.Instance.weightCounter);
((TMP_Text)staminaNumber).transform.SetParent(((Component)WeightCounter.phtUI).transform, false);
((TMP_Text)staminaNumber).transform.position = ((TMP_Text)HUDManager.Instance.weightCounter).transform.position;
((TMP_Text)staminaNumber).transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
Transform transform = ((TMP_Text)staminaNumber).transform;
transform.localPosition += new Vector3(-213f, 33f);
((TMP_Text)staminaNumber).alignment = (TextAlignmentOptions)260;
((TMP_Text)staminaNumber).margin = new Vector4(0f, 0f, 0f, 0f);
((TMP_Text)staminaNumber).lineSpacing = -10f;
((TMP_Text)staminaNumber).fontSize = 12f;
((Object)staminaNumber).name = "PHTStaminaNumber";
((Graphic)staminaNumber).color = StaminaMeter.colorNotExhausted;
((TMP_Text)staminaNumber).text = "100%";
((TMP_Text)staminaNumber).alpha = 0f;
basePosition = ((TMP_Text)staminaNumber).transform.localPosition;
}
}
public static void Update()
{
//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.SN_enabled.Value || (Object)(object)HUDManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
{
((TMP_Text)staminaNumber).alpha = 0f;
return;
}
SetBaseStaminaConfiguration();
int num = Mathf.Clamp((int)(100f * GameNetworkManager.Instance.localPlayerController.sprintMeter), 0, 999);
((TMP_Text)staminaNumber).text = $"{num}%";
if (!Plugin.SM_fadeToRed.Value)
{
((Graphic)staminaNumber).color = StaminaMeter.colorNotExhausted;
}
else
{
((Graphic)staminaNumber).color = Color.Lerp(StaminaMeter.colorNotExhausted, StaminaMeter.colorExhausted, StaminaMeter.staminaColorTransitionTime);
}
}
private static void SetBaseStaminaConfiguration()
{
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
((TMP_Text)staminaNumber).alpha = 1f;
((TMP_Text)staminaNumber).transform.localPosition = basePosition + new Vector3(Plugin.SN_xOffset.Value, Plugin.SN_yOffset.Value);
((TMP_Text)staminaNumber).font = (Plugin.SN_textShadow.Value ? ((TMP_Text)HUDManager.Instance.planetRiskLevelText).font : ((TMP_Text)HUDManager.Instance.totalValueText).font);
}
}
internal class WeightCounter
{
private class WeightSection
{
public float textSize;
public Color textColor;
public WeightSection(float textSize, Color textColor)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
this.textSize = textSize;
this.textColor = textColor;
}
}
private static TextMeshProUGUI weightCounter = null;
private static Animator weightCounterAnimator = null;
public static Animator phtUI = null;
private static readonly Dictionary<Plugin.DisplayMetric, Dictionary<Plugin.MetricDisplayType, string>> Labels = new Dictionary<Plugin.DisplayMetric, Dictionary<Plugin.MetricDisplayType, string>>
{
{
Plugin.DisplayMetric.Pounds,
new Dictionary<Plugin.MetricDisplayType, string>
{
{
Plugin.MetricDisplayType.Default,
"lb"
},
{
Plugin.MetricDisplayType.Abbreviated,
"lb."
},
{
Plugin.MetricDisplayType.Full,
"pounds"
}
}
},
{
Plugin.DisplayMetric.Kilograms,
new Dictionary<Plugin.MetricDisplayType, string>
{
{
Plugin.MetricDisplayType.Default,
"kg"
},
{
Plugin.MetricDisplayType.Abbreviated,
"kg."
},
{
Plugin.MetricDisplayType.Full,
"kilograms"
}
}
},
{
Plugin.DisplayMetric.Grams,
new Dictionary<Plugin.MetricDisplayType, string>
{
{
Plugin.MetricDisplayType.Default,
"g"
},
{
Plugin.MetricDisplayType.Abbreviated,
"g."
},
{
Plugin.MetricDisplayType.Full,
"grams"
}
}
}
};
private static float displayWeight = 0f;
private static float startDisplayWeight = 0f;
private static float targetWeight = 0f;
private static float runtime = 0f;
private static float startFontSize = -1f;
private static readonly Dictionary<float, WeightSection> LbToSection = new Dictionary<float, WeightSection>
{
{
0f,
new WeightSection(1f, ColorByte(126, 126, 126))
},
{
0.01f,
new WeightSection(1.01f, ColorByte(250, 250, 185))
},
{
10f,
new WeightSection(1.05f, ColorByte(242, 242, 69))
},
{
20f,
new WeightSection(1.1f, ColorByte(235, 169, 55))
},
{
50f,
new WeightSection(1.25f, ColorByte(225, 90, 33))
},
{
80f,
new WeightSection(1.4f, ColorByte(220, 30, 30))
},
{
120f,
new WeightSection(1.67f, ColorByte(220, 42, 105))
},
{
180f,
new WeightSection(1.8f, ColorByte(126, 18, 196))
},
{
240f,
new WeightSection(1.9f, ColorByte(33, 33, 180))
},
{
315f,
new WeightSection(2f, ColorByte(2, 3, 15))
}
};
public static bool weightCounterWaitedFrame = false;
public static bool weightCounterStarted = false;
private static bool initialFontTypeValue = true;
private static float WeightInLb => (GameNetworkManager.Instance.localPlayerController.carryWeight - 1f) * 105f;
private static float DisplayWeightInLb => displayWeight;
private static float DisplayWeightInKg => DisplayWeightInLb * 0.453592f;
private static float DisplayWeightInGrams => DisplayWeightInLb * 453.592f;
private static WeightSection CurrentWeightSection => GetCurrentWeightSection(DisplayWeightInLb);
private static Color ColorByte(byte r, byte g, byte b)
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
return new Color((float)(int)r / 255f, (float)(int)g / 255f, (float)(int)b / 255f);
}
private static WeightSection GetCurrentWeightSection(float lb)
{
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
if (lb < 0.01f)
{
return LbToSection.First().Value;
}
if (lb >= 315f)
{
return LbToSection.Last().Value;
}
float num = 0f;
float num2 = 1f;
Color textColor = default(Color);
((Color)(ref textColor))..ctor(0.5f, 0.5f, 0.5f);
foreach (KeyValuePair<float, WeightSection> item in LbToSection)
{
if (lb < item.Key)
{
float num3 = Mathf.InverseLerp(num, item.Key, lb);
float textSize = Mathf.Lerp(num2, item.Value.textSize, num3);
Color textColor2 = Color.Lerp(textColor, item.Value.textColor, num3);
return new WeightSection(textSize, textColor2);
}
num = item.Key;
num2 = item.Value.textSize;
textColor = item.Value.textColor;
}
return LbToSection.First().Value;
}
public static void Start()
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.WC_enableTweaks.Value)
{
weightCounter = null;
weightCounterAnimator = null;
return;
}
weightCounter = HUDManager.Instance.weightCounter;
weightCounterAnimator = HUDManager.Instance.weightCounterAnimator;
TextMeshProUGUI obj = weightCounter;
((TMP_Text)obj).margin = ((TMP_Text)obj).margin + new Vector4(0f, 0f, -500f, 0f);
startDisplayWeight = 0f;
displayWeight = 0f;
targetWeight = 0f;
runtime = 0f;
if (startFontSize == -1f)
{
startFontSize = ((TMP_Text)weightCounter).fontSize;
}
if (Plugin.WC_betterFontType.Value)
{
((TMP_Text)weightCounter).font = ((TMP_Text)HUDManager.Instance.planetRiskLevelText).font;
}
}
public static void CreateWeightUIClone()
{
if (!((Object)(object)phtUI != (Object)null))
{
phtUI = Object.Instantiate<Animator>(HUDManager.Instance.weightCounterAnimator, ((Component)HUDManager.Instance.weightCounterAnimator).transform.parent);
((Object)phtUI).name = "PHTWeightUIClone";
Object.Destroy((Object)(object)((Component)((Component)phtUI).transform.GetChild(0)).gameObject);
}
}
public static void Update()
{
if (!weightCounterStarted && weightCounterWaitedFrame)
{
weightCounterStarted = true;
Start();
}
if (!weightCounterWaitedFrame)
{
weightCounterWaitedFrame = true;
}
if (!((Object)(object)weightCounter == (Object)null) && !((Object)(object)weightCounterAnimator == (Object)null))
{
UpdateWeightCounts();
UpdateWeightNumber();
UpdateWeightFormatting();
if (initialFontTypeValue != Plugin.WC_betterFontType.Value)
{
initialFontTypeValue = Plugin.WC_betterFontType.Value;
((TMP_Text)weightCounter).font = (initialFontTypeValue ? ((TMP_Text)HUDManager.Instance.planetRiskLevelText).font : ((TMP_Text)HUDManager.Instance.totalValueText).font);
}
}
}
private static void UpdateWeightCounts()
{
if (WeightInLb != targetWeight)
{
targetWeight = WeightInLb;
startDisplayWeight = displayWeight;
runtime = 0f;
}
if (displayWeight != targetWeight)
{
runtime += Time.deltaTime;
float num = ((targetWeight > displayWeight) ? Plugin.WC_countupTime.Value : Plugin.WC_countdownTime.Value);
if (runtime >= num || num == 0f)
{
displayWeight = targetWeight;
runtime = 0f;
}
else
{
displayWeight = Mathf.Lerp(startDisplayWeight, targetWeight, runtime / num);
}
}
}
private static void UpdateWeightNumber()
{
bool value = Plugin.WC_showDecimal.Value;
float num = DisplayWeightInLb;
switch (Plugin.WC_metric.Value)
{
case Plugin.DisplayMetric.Grams:
num = DisplayWeightInGrams;
break;
case Plugin.DisplayMetric.Kilograms:
num = DisplayWeightInKg;
break;
}
if (value)
{
num *= 10f;
}
switch (Plugin.WC_weightDisplayRounding.Value)
{
case Plugin.RoundingOptions.Floor:
num = Mathf.Floor(num);
break;
case Plugin.RoundingOptions.Round:
num = Mathf.Round(num);
break;
case Plugin.RoundingOptions.Ceiling:
num = Mathf.Ceil(num);
break;
}
if (value)
{
num /= 10f;
}
int num2 = (int)num;
int num3 = Mathf.RoundToInt(num * 10f) % 10;
string text = Labels[Plugin.WC_metric.Value][Plugin.WC_metricDisplayType.Value];
string text2 = num2.ToString();
if (value)
{
text2 += $".{num3}";
}
text2 = text2 + " " + text;
((TMP_Text)weightCounter).text = text2;
}
private static void UpdateWeightFormatting()
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
if (!Plugin.WC_customFormatting.Value)
{
((TMP_Text)weightCounter).fontSize = startFontSize;
weightCounterAnimator.SetFloat("weight", DisplayWeightInLb / 130f);
return;
}
weightCounterAnimator.SetFloat("weight", 0f);
WeightSection currentWeightSection = CurrentWeightSection;
string text = "#" + ColorUtility.ToHtmlStringRGB(currentWeightSection.textColor);
((TMP_Text)weightCounter).text = "<color=" + text + ">" + ((TMP_Text)weightCounter).text + "</color>";
((TMP_Text)weightCounter).fontSize = startFontSize * currentWeightSection.textSize;
}
}
}
namespace PlayerHUDTweaks.Patches
{
[HarmonyPatch(typeof(HUDManager))]
internal class HUDManagerPatch
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void Start_Postfix()
{
WeightCounter.CreateWeightUIClone();
HealthImage.Start();
HealthNumber.Start();
StaminaNumber.Start();
BatteryNumber.Start();
WeightCounter.weightCounterStarted = false;
WeightCounter.weightCounterWaitedFrame = false;
}
[HarmonyPatch("UpdateHealthUI")]
[HarmonyPostfix]
private static void UpdateHealthUI_Postfix(ref int health)
{
HealthImage.OnHealthChange(health);
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void Update_Postfix()
{
if (Plugin.HI_updateEveryFrame.Value && (Object)(object)GameNetworkManager.Instance?.localPlayerController != (Object)null && !GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
HealthImage.OnHealthChange(GameNetworkManager.Instance.localPlayerController.health);
}
HealthNumber.Update();
StaminaNumber.Update();
BatteryNumber.Update();
WeightCounter.Update();
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("KillPlayer")]
[HarmonyPostfix]
private static void KillPlayer_Postfix(ref PlayerControllerB __instance)
{
if (!((Object)(object)__instance != (Object)(object)GameNetworkManager.Instance.localPlayerController) && GameNetworkManager.Instance.localPlayerController.AllowPlayerDeath())
{
HealthImage.OnHealthChange(0);
}
}
[HarmonyPatch("ConnectClientToPlayerObject")]
[HarmonyPostfix]
private static void Awake_Postfix(ref PlayerControllerB __instance)
{
if (!((Object)(object)__instance != (Object)(object)GameNetworkManager.Instance?.localPlayerController))
{
StaminaMeter.Start();
}
}
[HarmonyPatch("LateUpdate")]
[HarmonyPostfix]
private static void LateUpdate_Postfix(ref PlayerControllerB __instance)
{
if (!((Object)(object)__instance != (Object)(object)GameNetworkManager.Instance?.localPlayerController))
{
StaminaMeter.Update(__instance.sprintMeter);
}
}
}
}