Decompiled source of HudStar v2.4.2

HudStar.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HudStar")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HudStar")]
[assembly: AssemblyTitle("HudStar")]
[assembly: AssemblyVersion("1.0.0.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 HudStar
{
	[BepInPlugin("Harchytek.HudStar", "HudStar", "2.4.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class HudStarPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(EnemyHud), "UpdateHuds")]
		public static class EnemyHud_UpdateHuds_Patch
		{
			[HarmonyPriority(0)]
			[HarmonyPostfix]
			private static void Postfix(EnemyHud __instance)
			{
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_017a: 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_0245: Unknown result type (might be due to invalid IL or missing references)
				//IL_0253: Unknown result type (might be due to invalid IL or missing references)
				//IL_0262: Unknown result type (might be due to invalid IL or missing references)
				IDictionary value = Traverse.Create((object)__instance).Field("m_huds").GetValue<IDictionary>();
				if (value == null)
				{
					return;
				}
				foreach (DictionaryEntry item2 in value)
				{
					object value2 = item2.Value;
					Character value3 = Traverse.Create(value2).Field("m_character").GetValue<Character>();
					if ((Object)(object)value3 != (Object)null)
					{
						string item = ((Object)((Component)value3).gameObject).name.Replace("(Clone)", "").Trim();
						if (BossBlacklist.Contains(item))
						{
							continue;
						}
					}
					GameObject value4 = Traverse.Create(value2).Field("m_gui").GetValue<GameObject>();
					if ((Object)(object)value4 == (Object)null || !value4.activeInHierarchy)
					{
						continue;
					}
					List<RectTransform> list = new List<RectTransform>();
					for (int i = 0; i < value4.transform.childCount; i++)
					{
						Transform child = value4.transform.GetChild(i);
						if (!((Component)child).gameObject.activeSelf)
						{
							continue;
						}
						string text = ((Object)child).name.ToLower();
						if (!text.Contains("level") && !text.Contains("star") && !text.Contains("darken") && !text.Contains("hc_"))
						{
							continue;
						}
						RectTransform component = ((Component)child).GetComponent<RectTransform>();
						if ((Object)(object)component != (Object)null)
						{
							HudStarMarker component2 = ((Component)child).GetComponent<HudStarMarker>();
							if ((Object)(object)component2 == (Object)null)
							{
								component2 = ((Component)child).gameObject.AddComponent<HudStarMarker>();
								component2.originalPos = component.anchoredPosition;
								component2.originalScale = ((Transform)component).localScale;
							}
							list.Add(component);
						}
					}
					int count = list.Count;
					for (int j = 0; j < count; j++)
					{
						RectTransform val = list[j];
						HudStarMarker component3 = ((Component)val).GetComponent<HudStarMarker>();
						if (!((Object)(object)component3 == (Object)null))
						{
							float num = ((!AutoCenter.Value || count <= 0) ? (component3.originalPos.x + OffsetX.Value) : (((float)j - (float)(count - 1) / 2f) * 18f + OffsetX.Value));
							float num2 = component3.originalPos.y + OffsetY.Value;
							val.anchoredPosition = new Vector2(num, num2);
							((Transform)val).localScale = component3.originalScale * Scale.Value;
						}
					}
				}
			}
		}

		public class HudStarMarker : MonoBehaviour
		{
			public Vector2 originalPos;

			public Vector3 originalScale;
		}

		public const string ModGUID = "Harchytek.HudStar";

		public const string ModName = "HudStar";

		public const string ModVersion = "2.4.2";

		public static ConfigEntry<float> OffsetX;

		public static ConfigEntry<float> OffsetY;

		public static ConfigEntry<float> Scale;

		public static ConfigEntry<bool> AutoCenter;

		private static readonly HashSet<string> BossBlacklist = new HashSet<string> { "Eikthyr", "gd_king", "Bonemass", "Dragon", "GoblinKing", "Queen", "SeekerQueen", "Fader" };

		private void Awake()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			OffsetX = ((BaseUnityPlugin)this).Config.Bind<float>("HUD Creature", "StarOffsetX", 0f, "Horizontal offset for all stars.");
			OffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("HUD Creature", "StarOffsetY", 0f, "Vertical offset for all stars.");
			Scale = ((BaseUnityPlugin)this).Config.Bind<float>("HUD Creature", "StarScale", 1f, "Star size scale.");
			AutoCenter = ((BaseUnityPlugin)this).Config.Bind<bool>("HUD Creature", "AutoCenterStars", true, "Automatically center stars horizontally (1 star centered, 2 stars aligned around middle).");
			new Harmony("harchytek.hudstar").PatchAll();
		}
	}
}