Decompiled source of ErenshorLevelDisplay v1.1.0

Drizzlx.Erenshor.LevelDisplay.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Linq;
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 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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Drizzlx.Erenshor.LevelDisplay")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c2d757edd72507fc9634e0ef6b15b7fa0c49d966")]
[assembly: AssemblyProduct("LevelDisplay")]
[assembly: AssemblyTitle("Drizzlx.Erenshor.LevelDisplay")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace LevelDisplay
{
	[BepInPlugin("Drizzlx.Erenshor.LevelDisplay", "LevelDisplay", "1.0.0")]
	public class LevelDisplayPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static ConfigEntry<bool> DisplaySimPlayerLevelAboveHead;

		public static ConfigEntry<bool> DisplayMobLevelAboveHead;

		public static ConfigEntry<float> DisplayNamePlateRangeMultiplier;

		private void Awake()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			InitializeConfigurations();
			_harmony = new Harmony("Drizzlx.Erenshor.LevelDisplay");
			_harmony.PatchAll();
		}

		private void InitializeConfigurations()
		{
			DisplaySimPlayerLevelAboveHead = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "DisplaySimPlayerLevelAboveHead", false, "Whether to display levels for SimPlayer NPCs.");
			DisplayMobLevelAboveHead = ((BaseUnityPlugin)this).Config.Bind<bool>("Display", "DisplayMobLevelAboveHead", true, "Whether to display levels for Mobs.");
			DisplayNamePlateRangeMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Display", "DisplayNameTagRangeMultiplier", 1.5f, "Multiplier for distance to render mob name tags.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Drizzlx.Erenshor.LevelDisplay";

		public const string PLUGIN_NAME = "LevelDisplay";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace LevelDisplay.patch
{
	[HarmonyPatch(typeof(NPC), "Start")]
	public static class NamePlatePatch
	{
		private static readonly string[] _bankNpcs = new string[4] { "Prestigio Valusha", "Validus Greencent", "Comstock Retalio", "Summoned: Pocket Rift" };

		private static readonly string[] _otherNpcs = new string[2] { "Thella Steepleton", "Goldie Retalio" };

		[HarmonyPostfix]
		public static void Postfix(NPC __instance)
		{
			FieldInfo field = typeof(NPC).GetField("MyStats", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(NPC).GetField("Myself", BindingFlags.Instance | BindingFlags.NonPublic);
			if (!(field != null) || !(field2 != null))
			{
				return;
			}
			object? value = field.GetValue(__instance);
			Stats val = (Stats)((value is Stats) ? value : null);
			object? value2 = field2.GetValue(__instance);
			Character val2 = (Character)((value2 is Character) ? value2 : null);
			Transform namePlate = __instance.NamePlate;
			TextMeshPro val3 = ((namePlate != null) ? ((Component)namePlate).GetComponent<TextMeshPro>() : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null)
			{
				return;
			}
			if (val2.MyNPC.SimPlayer)
			{
				if (LevelDisplayPlugin.DisplaySimPlayerLevelAboveHead.Value)
				{
					((TMP_Text)val3).text = __instance.NPCName + " [" + val.Level + "]";
					if (__instance.GuildName != "")
					{
						((TMP_Text)val3).text = ((TMP_Text)val3).text + "\n<" + __instance.GuildName + ">";
					}
				}
			}
			else if (IsMob(__instance) && LevelDisplayPlugin.DisplayMobLevelAboveHead.Value)
			{
				((TMP_Text)val3).text = __instance.NPCName + " [" + val.Level + "]";
			}
		}

		public static bool IsMob(NPC npc)
		{
			FieldInfo field = typeof(NPC).GetField("Myself", BindingFlags.Instance | BindingFlags.NonPublic);
			if (field == null)
			{
				return false;
			}
			object? value = field.GetValue(npc);
			Character val = (Character)((value is Character) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			NPCDialogManager component = ((Component)val).GetComponent<NPCDialogManager>();
			if (npc.SimPlayer || (Object)(object)component != (Object)null || val.isVendor || _bankNpcs.Contains(val.MyNPC.NPCName) || _otherNpcs.Contains(val.MyNPC.NPCName) || val.MiningNode)
			{
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(NPC), "HandleNameTag")]
	public static class NameTagRenderDistancePatch
	{
		[HarmonyPostfix]
		public static void Postfix(NPC __instance)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: 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)
			if (!__instance.SimPlayer && GameData.ShowNPCName == 0 && NamePlatePatch.IsMob(__instance))
			{
				if (!((Component)__instance.NamePlate).gameObject.activeSelf && (double)Vector3.Distance(((Component)__instance).transform.position, GameData.GameCamPos.position) < 25.0 * (double)LevelDisplayPlugin.DisplayNamePlateRangeMultiplier.Value)
				{
					((Component)__instance.NamePlate).transform.LookAt(GameData.GameCamPos);
					((Component)__instance.NamePlate).gameObject.SetActive(true);
				}
				else if (((Component)__instance.NamePlate).gameObject.activeSelf && !((double)Vector3.Distance(((Component)__instance).transform.position, GameData.GameCamPos.position) <= 25.0 * (double)LevelDisplayPlugin.DisplayNamePlateRangeMultiplier.Value))
				{
					((Component)__instance.NamePlate).transform.LookAt(GameData.GameCamPos);
					((Component)__instance.NamePlate).gameObject.SetActive(false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControl), "Update")]
	public static class TargetNamePatch
	{
		[HarmonyPostfix]
		public static void Postfix(PlayerControl __instance)
		{
			Character currentTarget = __instance.CurrentTarget;
			if (!((Object)(object)currentTarget != (Object)null) || !(((Object)((Component)currentTarget).transform).name != "Player") || !NamePlatePatch.IsMob(currentTarget.MyNPC))
			{
				return;
			}
			FieldInfo field = typeof(NPC).GetField("MyStats", BindingFlags.Instance | BindingFlags.NonPublic);
			if (!(field == null))
			{
				object? value = field.GetValue(currentTarget.MyNPC);
				Stats val = (Stats)((value is Stats) ? value : null);
				if (!((Object)(object)val == (Object)null))
				{
					((TMP_Text)__instance.TargetName).text = ((Object)((Component)__instance.CurrentTarget).transform).name + " (" + val.Level + ")";
				}
			}
		}
	}
}