Decompiled source of SB Death Icon v0.1.0

BepInEx/plugins/SBDeathIcon/SBDeathIcon.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
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 BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("SBDeathIcon")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SBDeathIcon")]
[assembly: AssemblyTitle("SBDeathIcon")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace SBDeathIcon
{
	[BepInPlugin("com.samdb.sb-death-icon", "SB Death Icon", "0.1.0")]
	public sealed class Plugin : BasePlugin
	{
		public const string PluginGuid = "com.samdb.sb-death-icon";

		public const string PluginName = "SB Death Icon";

		public const string PluginVersion = "0.1.0";

		internal static Plugin Instance { get; private set; }

		internal static ConfigEntry<float> MarkerLifetime { get; private set; }

		internal static ConfigEntry<float> MarkerSize { get; private set; }

		public override void Load()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			Instance = this;
			ClassInjector.RegisterTypeInIl2Cpp<Billboard>();
			MarkerLifetime = ((BasePlugin)this).Config.Bind<float>("Marker", "Lifetime", 2.5f, "How long the SB marker remains visible.");
			MarkerSize = ((BasePlugin)this).Config.Bind<float>("Marker", "Size", 0.2f, "World-space size of the SB marker.");
			Harmony harmony = new Harmony("com.samdb.sb-death-icon");
			DeathHooks.Install(harmony, ((BasePlugin)this).Log);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("SB Death Icon");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.1.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
			}
			log.LogInfo(val);
		}
	}
	internal static class DeathHooks
	{
		private static readonly string[] CandidateMethods = new string[3] { "OnDead", "Die", "OnDeath" };

		private static readonly HashSet<int> SeenAgents = new HashSet<int>();

		public static void Install(Harmony harmony, ManualLogSource log)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			Type type = AccessTools.TypeByName("EnemyAgent");
			if (type == null)
			{
				log.LogError((object)"EnemyAgent was not found. The plugin will remain loaded but cannot display markers.");
				return;
			}
			int num = 0;
			string[] candidateMethods = CandidateMethods;
			bool flag = default(bool);
			foreach (string text in candidateMethods)
			{
				MethodInfo methodInfo = AccessTools.Method(type, text, (Type[])null, (Type[])null);
				if (!(methodInfo == null))
				{
					harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(DeathHooks), "OnEnemyDeath", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Patched ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(type.FullName);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
					}
					log.LogInfo(val);
				}
			}
			if (num == 0)
			{
				log.LogWarning((object)"No known EnemyAgent death method was found.");
			}
		}

		private static void OnEnemyDeath(object __instance)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			Component val = (Component)((__instance is Component) ? __instance : null);
			if (val == null)
			{
				return;
			}
			int instanceID = ((Object)val).GetInstanceID();
			lock (SeenAgents)
			{
				if (!SeenAgents.Add(instanceID))
				{
					return;
				}
			}
			SBMarker.Create(val.transform.position);
		}
	}
	internal static class SBMarker
	{
		public static void Create(Vector3 position)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("SBDeathIcon");
			val.transform.position = position + Vector3.up * 1.1f;
			TextMesh val2 = val.AddComponent<TextMesh>();
			val2.text = "SB";
			val2.characterSize = Plugin.MarkerSize.Value;
			val2.fontSize = 96;
			val2.fontStyle = (FontStyle)1;
			val2.anchor = (TextAnchor)4;
			val2.alignment = (TextAlignment)1;
			val2.color = Color.red;
			MeshRenderer component = val.GetComponent<MeshRenderer>();
			if ((Object)(object)component != (Object)null)
			{
				((Renderer)component).material.color = Color.red;
			}
			val.AddComponent<Billboard>();
			Object.Destroy((Object)(object)val, Mathf.Max(0.1f, Plugin.MarkerLifetime.Value));
		}
	}
	internal sealed class Billboard : MonoBehaviour
	{
		public Billboard(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if (!((Object)(object)main == (Object)null))
			{
				((Component)this).transform.forward = ((Component)main).transform.forward;
			}
		}
	}
}