Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ShowEncumbrance v1.0.1
ShowEncumbrance.dll
Decompiled a week agousing System; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.UI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("ShowEncumbrance")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.1.0")] [assembly: AssemblyInformationalVersion("1.0.1")] [assembly: AssemblyProduct("ShowEncumbrance")] [assembly: AssemblyTitle("ShowEncumbrance")] [assembly: AssemblyVersion("1.0.1.0")] [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 ShowEncumbrance { [BepInPlugin("com.dreich.showencumbrance", "Show Encumbrance", "1.0.1")] public class ShowEncumbrancePlugin : BaseUnityPlugin { public const string Guid = "com.dreich.showencumbrance"; public const string Name = "Show Encumbrance"; public const string Version = "1.0.1"; private const string JatifyGuid = "jatify.ui"; private const string ToolsBarName = "ToolsBar"; private const float SearchInterval = 1f; private const float JatifyGap = 8f; private const float VanillaSize = 64f; private const float VanillaMargin = 24f; private const float DefaultWarnPercent = 90f; private const float MaxWarnPercent = 100f; internal static ConfigEntry<bool> ShowNumbers; internal static ConfigEntry<float> WarnPercent; private bool jatify; private float nextSearch; private RectTransform toolsBar; private Gauge gauge; private void Awake() { //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Expected O, but got Unknown ShowNumbers = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowNumbers", true, "Show the weight you're carrying and how much you can carry under the icon."); WarnPercent = ((BaseUnityPlugin)this).Config.Bind<float>("General", "WarnPercent", 90f, new ConfigDescription("How full, in percent, before the ring turns to its warning colour.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>())); } private void Start() { jatify = Chainloader.PluginInfos.ContainsKey("jatify.ui"); } private void Update() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)Hud.instance == (Object)null || (Object)(object)localPlayer == (Object)null) { gauge?.Hide(); return; } if (jatify) { LookForToolsBar(); } bool flag = (Object)(object)toolsBar != (Object)null; if (gauge != null && (!gauge.Alive || gauge.BesideTools != flag)) { gauge.Destroy(); gauge = null; } if (gauge == null) { gauge = (flag ? AttachToJatify() : AttachToVanilla()); } if (gauge != null && (!flag || FollowToolsBar())) { gauge.Show(((Humanoid)localPlayer).GetInventory().GetTotalWeight(), localPlayer.GetMaxCarryWeight()); } } private void LookForToolsBar() { if (!((Object)(object)toolsBar != (Object)null) && !(Time.unscaledTime < nextSearch)) { nextSearch = Time.unscaledTime + 1f; GameObject val = GameObject.Find("ToolsBar"); RectTransform val2 = (RectTransform)(((Object)(object)val != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); toolsBar = (((Object)(object)val2 != (Object)null && (Object)(object)((Transform)val2).parent != (Object)null) ? val2 : null); } } private Gauge AttachToVanilla() { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_004f: 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_0056: 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) GameObject rootObject = Hud.instance.m_rootObject; if ((Object)(object)rootObject == (Object)null) { return null; } Gauge obj = new Gauge(rootObject.transform, 64f, rootObject.GetComponentInChildren<TMP_Text>(true), besideTools: false); RectTransform root = obj.Root; Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(1f, 0f); root.pivot = val; Vector2 anchorMin = (root.anchorMax = val); root.anchorMin = anchorMin; root.anchoredPosition = new Vector2(-24f, 24f); return obj; } private Gauge AttachToJatify() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) Transform parent = ((Transform)toolsBar).parent; Rect rect = toolsBar.rect; Gauge result = (gauge = new Gauge(parent, ((Rect)(ref rect)).height, ((Component)toolsBar).GetComponentInChildren<TMP_Text>(true), besideTools: true)); PlaceBesideToolsBar(); return result; } private bool FollowToolsBar() { bool activeSelf = ((Component)toolsBar).gameObject.activeSelf; gauge.SetVisible(activeSelf); if (activeSelf) { PlaceBesideToolsBar(); } return activeSelf; } private void PlaceBesideToolsBar() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_005e: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) //IL_009a: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: 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_00e5: Unknown result type (might be due to invalid IL or missing references) RectTransform root = gauge.Root; Rect rect = toolsBar.rect; float height = ((Rect)(ref rect)).height; float x = toolsBar.anchoredPosition.x; float x2 = toolsBar.pivot.x; rect = toolsBar.rect; float num = x - x2 * ((Rect)(ref rect)).width; float num2 = toolsBar.anchoredPosition.y + (0.5f - toolsBar.pivot.y) * height; root.anchorMin = toolsBar.anchorMin; root.anchorMax = toolsBar.anchorMax; root.pivot = new Vector2(1f, 0.5f); root.sizeDelta = new Vector2(height, height); Vector2 val = default(Vector2); ((Vector2)(ref val))..ctor(num - 8f, num2); if (root.anchoredPosition != val) { root.anchoredPosition = val; } } private void OnDestroy() { gauge?.Destroy(); } } internal sealed class Gauge { private const string RootName = "ShowEncumbrance"; private const float IconScale = 0.55f; private const float TextHeight = 18f; private const float TextGap = 2f; private const float TextWidthScale = 2.5f; private const float FontSize = 14f; private static readonly Color TrackColor = new Color(0f, 0f, 0f, 0.55f); private static readonly Color FillColor = new Color(0.92f, 0.88f, 0.78f); private static readonly Color WarnColor = new Color(1f, 0.78f, 0.3f); private static readonly Color OverColor = new Color(1f, 0.35f, 0.3f); private static readonly Color IconColor = Color.white; private readonly Image fill; private readonly Image icon; private readonly TMP_Text numbers; private int shownWeight = -1; private int shownMax = -1; internal RectTransform Root { get; } internal bool Alive => (Object)(object)Root != (Object)null; internal bool BesideTools { get; } internal Gauge(Transform parent, float size, TMP_Text fontSource, bool besideTools) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_012f: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Expected O, but got Unknown //IL_0194: Unknown result type (might be due to invalid IL or missing references) //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01ab: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01d6: Unknown result type (might be due to invalid IL or missing references) BesideTools = besideTools; Root = new GameObject("ShowEncumbrance", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>(); ((Transform)Root).SetParent(parent, false); Root.sizeDelta = new Vector2(size, size); ((Graphic)Layer("Track", Ring.Shape)).color = TrackColor; fill = Layer("Fill", Ring.Shape); fill.type = (Type)3; fill.fillMethod = (FillMethod)4; fill.fillOrigin = 2; fill.fillClockwise = true; icon = Layer("Icon", null); icon.preserveAspect = true; RectTransform rectTransform = ((Graphic)icon).rectTransform; float num = 0.225f; rectTransform.anchorMin = new Vector2(num, num); rectTransform.anchorMax = new Vector2(1f - num, 1f - num); GameObject val = new GameObject("Numbers", new Type[1] { typeof(RectTransform) }); val.SetActive(false); numbers = (TMP_Text)(object)val.AddComponent<TextMeshProUGUI>(); numbers.font = (((Object)(object)fontSource != (Object)null) ? fontSource.font : AnyFont()); RectTransform rectTransform2 = numbers.rectTransform; ((Transform)rectTransform2).SetParent((Transform)(object)Root, false); Vector2 val2 = default(Vector2); ((Vector2)(ref val2))..ctor(0.5f, 0f); rectTransform2.anchorMax = val2; rectTransform2.anchorMin = val2; rectTransform2.pivot = new Vector2(0.5f, 1f); rectTransform2.anchoredPosition = new Vector2(0f, -2f); rectTransform2.sizeDelta = new Vector2(size * 2.5f, 18f); numbers.fontSize = 14f; numbers.alignment = (TextAlignmentOptions)258; numbers.textWrappingMode = (TextWrappingModes)0; ((Graphic)numbers).raycastTarget = false; val.SetActive(true); } private static TMP_FontAsset AnyFont() { return Resources.FindObjectsOfTypeAll<TMP_FontAsset>().FirstOrDefault(); } private Image Layer(string name, Sprite sprite) { //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) Image obj = new GameObject(name, new Type[1] { typeof(RectTransform) }).AddComponent<Image>(); RectTransform rectTransform = ((Graphic)obj).rectTransform; ((Transform)rectTransform).SetParent((Transform)(object)Root, false); rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; Vector2 offsetMin = (rectTransform.offsetMax = Vector2.zero); rectTransform.offsetMin = offsetMin; obj.sprite = sprite; ((Graphic)obj).raycastTarget = false; return obj; } internal void Show(float weight, float max) { //IL_00e0: Unknown result type (might be due to invalid IL or missing references) //IL_00e5: 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_00d9: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_011a: Unknown result type (might be due to invalid IL or missing references) //IL_0113: Unknown result type (might be due to invalid IL or missing references) //IL_014d: Unknown result type (might be due to invalid IL or missing references) SetVisible(visible: true); if ((Object)(object)icon.sprite == (Object)null) { icon.sprite = EncumberedIcon(); } ((Behaviour)icon).enabled = (Object)(object)icon.sprite != (Object)null; int num = Mathf.RoundToInt(weight); int num2 = Mathf.RoundToInt(max); bool value = ShowEncumbrancePlugin.ShowNumbers.Value; if (((Component)numbers).gameObject.activeSelf != value) { ((Component)numbers).gameObject.SetActive(value); } if (num != shownWeight || num2 != shownMax) { shownWeight = num; shownMax = num2; float num3 = ((max > 0f) ? (weight / max) : 1f); Color color = ((num3 > 1f) ? OverColor : ((num3 * 100f >= ShowEncumbrancePlugin.WarnPercent.Value) ? WarnColor : FillColor)); fill.fillAmount = Mathf.Clamp01(num3); ((Graphic)fill).color = color; ((Graphic)icon).color = ((num3 > 1f) ? OverColor : IconColor); numbers.text = num + "/" + num2; ((Graphic)numbers).color = color; } } internal void SetVisible(bool visible) { if (((Component)Root).gameObject.activeSelf != visible) { ((Component)Root).gameObject.SetActive(visible); } } internal void Hide() { if (Alive) { SetVisible(visible: false); } } internal void Destroy() { if (Alive) { Object.Destroy((Object)(object)((Component)Root).gameObject); } } private static Sprite EncumberedIcon() { if ((Object)(object)ObjectDB.instance == (Object)null) { return null; } StatusEffect statusEffect = ObjectDB.instance.GetStatusEffect(SEMan.s_statusEffectEncumbered); if (!((Object)(object)statusEffect != (Object)null)) { return null; } return statusEffect.m_icon; } } internal static class Ring { private const int TextureSize = 128; private const float Thickness = 0.14f; private const float EdgeSoftness = 0.5f; private static Sprite sprite; internal static Sprite Shape { get { if (!((Object)(object)sprite != (Object)null)) { return sprite = Build(); } return sprite; } } private static Sprite Build() { //IL_000c: 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) //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Expected O, but got Unknown //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0058: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Unknown result type (might be due to invalid IL or missing references) //IL_00b5: 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) Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false) { filterMode = (FilterMode)1, wrapMode = (TextureWrapMode)1 }; float num = 64f; float num2 = num * 0.86f; Color32[] array = (Color32[])(object)new Color32[16384]; for (int i = 0; i < 128; i++) { for (int j = 0; j < 128; j++) { float num3 = Vector2.Distance(new Vector2((float)j + 0.5f, (float)i + 0.5f), new Vector2(num, num)); float num4 = Mathf.Clamp01(num - num3 + 0.5f) * Mathf.Clamp01(num3 - num2 + 0.5f); array[i * 128 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num4 * 255f)); } } val.SetPixels32(array); val.Apply(); return Sprite.Create(val, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f)); } } }