using System;
using System.Collections;
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.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
[assembly: AssemblyCompany("PlayerNametagTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Player nametag tweaks")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PlayerNametagTweaks")]
[assembly: AssemblyTitle("PlayerNametagTweaks")]
[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 PlayerNametagTweaks
{
[BepInPlugin("PlayerNametagTweaks", "PlayerNametagTweaks", "1.0.2")]
public class Plugin : BaseUnityPlugin
{
private Harmony harmony;
private ConfigEntry<float> nametagDistance;
private ConfigEntry<bool> scaleDownOverDistance;
private ConfigEntry<bool> showNametagsWhenSneaking;
private static FieldInfo playerPositionRefPointField = typeof(EnemyHud).GetField("m_refPoint", BindingFlags.Instance | BindingFlags.NonPublic);
private static FieldInfo hudsDictionaryField = typeof(EnemyHud).GetField("m_huds", BindingFlags.Instance | BindingFlags.NonPublic);
private static FieldInfo hudDataMainGuiField = typeof(EnemyHud).Assembly.GetType("EnemyHud+HudData").GetField("m_gui", BindingFlags.Instance | BindingFlags.Public);
public static Plugin Instance { get; private set; }
private void Awake()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
Instance = this;
harmony = new Harmony("main");
harmony.PatchAll(typeof(Plugin));
nametagDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Nametag Distance", 64f, (ConfigDescription)null);
scaleDownOverDistance = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Scale down nametag over distance", true, (ConfigDescription)null);
showNametagsWhenSneaking = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Show nametag when crouching", true, new ConfigDescription("Show player nametags when they're sneaking/crouching", (AcceptableValueBase)null, new object[0]));
}
[HarmonyPatch(typeof(EnemyHud), "TestShow")]
[HarmonyPostfix]
private static void ShowCharacterHudPostfix(ref EnemyHud __instance, ref bool __result, Character c, bool isVisible)
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)c == (Object)null || !c.IsPlayer() || (!Instance.showNametagsWhenSneaking.Value && c.IsCrouching()))
{
return;
}
float num = Vector3.Distance((Vector3)playerPositionRefPointField.GetValue(__instance), ((Component)c).transform.position);
if (!(num > Instance.nametagDistance.Value))
{
if (Instance.scaleDownOverDistance.Value && TryGetCharacterHudData(__instance, c, out var hudData))
{
HandleHudScaling(hudData, num);
}
__result = true;
}
}
private static void HandleHudScaling(object hudData, float distance)
{
//IL_004a: Unknown result type (might be due to invalid IL or missing references)
object? value = hudDataMainGuiField.GetValue(hudData);
GameObject val = (GameObject)((value is GameObject) ? value : null);
if (!((Object)(object)val == (Object)null))
{
float num = distance / Instance.nametagDistance.Value;
float num2 = 0.25f + 0.75f * (1f - num);
val.transform.localScale = new Vector3(num2, num2, num2);
}
}
private static bool TryGetCharacterHudData(EnemyHud hudController, Character character, out object hudData)
{
if (hudsDictionaryField.GetValue(hudController) is IDictionary dictionary)
{
foreach (DictionaryEntry item in dictionary)
{
if (item.Key != null && item.Value != null && item.Key == character)
{
hudData = item.Value;
return hudData != null;
}
}
}
hudData = null;
return false;
}
}
internal class PluginInfo
{
public const string PLUGIN_GUID = "PlayerNametagTweaks";
public const string PLUGIN_NAME = "PlayerNametagTweaks";
public const string PLUGIN_VERSION = "1.0.2";
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "PlayerNametagTweaks";
public const string PLUGIN_NAME = "PlayerNametagTweaks";
public const string PLUGIN_VERSION = "1.0.0";
}
}