Decompiled source of BioStickTracker v1.0.0

BioStickTracker.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GameData;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("0.0.0.0")]
[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.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
	[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 BioTrackerBeacon
{
	[BepInPlugin("BioStickTracker", "BioStickTracker", "1.0.0")]
	public sealed class BioStickTracker : BasePlugin
	{
		internal static ManualLogSource? Logger;

		internal static ConfigEntry<bool>? CfgDebugLog;

		internal static ConfigEntry<int>? CfgPersistentId;

		internal static ConfigEntry<float>? CfgTagRadius;

		internal static ConfigEntry<float>? CfgTickInterval;

		internal static ConfigEntry<bool>? CfgTagSleepers;

		internal static ConfigEntry<bool>? CfgTagShadows;

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			Logger = new ManualLogSource("BioStickTracker");
			CfgDebugLog = ((BasePlugin)this).Config.Bind<bool>("Debug", "Debug", false, "Enable debug logging.");
			CfgPersistentId = ((BasePlugin)this).Config.Bind<int>("General", "PersistentId", 0, "Only attach to glowsticks whose persistentID matches this value. Set 0 to work on all types of glowstick.");
			CfgTagRadius = ((BasePlugin)this).Config.Bind<float>("General", "TagRadius", 3f, "Scan radius around the glowstick (meters).");
			CfgTickInterval = ((BasePlugin)this).Config.Bind<float>("General", "TickInterval", 0.2f, "Scan interval (seconds).");
			CfgTagShadows = ((BasePlugin)this).Config.Bind<bool>("General", "TagShadows", false, "Tag Shadows?");
			CfgTagSleepers = ((BasePlugin)this).Config.Bind<bool>("General", "TagSleepers", true, "Tag Sleepers?");
			new Harmony("BioStickTracker").PatchAll();
			ClassInjector.RegisterTypeInIl2Cpp<GlowstickTagRuntime>();
		}
	}
	[HarmonyPatch(typeof(GlowstickInstance), "Setup")]
	[HarmonyPatch(new Type[] { typeof(ItemDataBlock) })]
	internal static class GlowstickPatcher
	{
		private static void Postfix(GlowstickInstance __instance, ItemDataBlock data)
		{
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			if ((Object)(object)__instance == (Object)null)
			{
				return;
			}
			int? num = BioStickTracker.CfgPersistentId.Value;
			bool flag = default(bool);
			if (num.HasValue && num > 0)
			{
				int num2;
				try
				{
					num2 = (int)(((GameDataBlockBase<ItemDataBlock>)(object)data)?.persistentID ?? 0);
				}
				catch
				{
					if (BioStickTracker.CfgDebugLog.Value)
					{
						ManualLogSource? logger = BioStickTracker.Logger;
						if (logger != null)
						{
							logger.LogWarning((object)"[Glowstick] persistentID read failed; skipped.");
						}
					}
					return;
				}
				if (num2 != num)
				{
					if (!BioStickTracker.CfgDebugLog.Value)
					{
						return;
					}
					ManualLogSource logger2 = BioStickTracker.Logger;
					if (logger2 != null)
					{
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Glowstick] pid mismatch; pid=");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" cfg=");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int?>(num);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" skipped.");
						}
						logger2.LogInfo(val);
					}
					return;
				}
			}
			GameObject gameObject;
			try
			{
				gameObject = ((Component)__instance).gameObject;
			}
			catch
			{
				return;
			}
			if ((Object)(object)gameObject == (Object)null)
			{
				return;
			}
			GlowstickTagRuntime component = gameObject.GetComponent<GlowstickTagRuntime>();
			if (!((Object)(object)component == (Object)null))
			{
				return;
			}
			component = gameObject.AddComponent<GlowstickTagRuntime>();
			component.Init(((Object)gameObject).GetInstanceID());
			component.Begin();
			if (!BioStickTracker.CfgDebugLog.Value)
			{
				return;
			}
			ManualLogSource logger3 = BioStickTracker.Logger;
			if (logger3 != null)
			{
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Glowstick] runtime attached GameObjectId=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(((Object)gameObject).GetInstanceID());
				}
				logger3.LogInfo(val);
			}
		}
	}
	internal sealed class GlowstickTagRuntime : MonoBehaviour
	{
		private const int HibernateStateValue = 14;

		private int _goId;

		private bool _started;

		private float _nextScanTime;

		public void Init(int goId)
		{
			_goId = goId;
		}

		public void Begin()
		{
			if (!_started)
			{
				_started = true;
				_nextScanTime = Time.realtimeSinceStartup + Random.Range(0f, 0.05f);
			}
		}

		private void Update()
		{
			if (_started)
			{
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				float num = Mathf.Max(0.05f, BioStickTracker.CfgTickInterval.Value);
				if (!(realtimeSinceStartup < _nextScanTime))
				{
					_nextScanTime = realtimeSinceStartup + num;
					Scan();
				}
			}
		}

		private void Scan()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: 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_011a: Expected O, but got Unknown
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Expected O, but got Unknown
			//IL_00e4: 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_0053: Expected O, but got Unknown
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Expected O, but got Unknown
			float num = Mathf.Max(0f, BioStickTracker.CfgTagRadius.Value);
			if (num <= 0f)
			{
				return;
			}
			Vector3 position = ((Component)this).transform.position;
			bool flag = default(bool);
			if (BioStickTracker.CfgDebugLog.Value)
			{
				ManualLogSource logger = BioStickTracker.Logger;
				if (logger != null)
				{
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(66, 5, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Glowstick] Scan start goId=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_goId);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" pos=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Vector3>(position);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" radius=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<float>(num, "F2");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" tagSleepers=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(BioStickTracker.CfgTagSleepers.Value);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" tagShadows=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(BioStickTracker.CfgTagShadows.Value);
					}
					logger.LogInfo(val);
				}
			}
			Collider[] array;
			try
			{
				array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(position, num, -1, (QueryTriggerInteraction)2));
			}
			catch (Exception ex)
			{
				if (!BioStickTracker.CfgDebugLog.Value)
				{
					return;
				}
				ManualLogSource logger2 = BioStickTracker.Logger;
				if (logger2 != null)
				{
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(40, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[Glowstick] OverlapSphere failed goId=");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<int>(_goId);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.GetType().Name);
					}
					logger2.LogWarning(val2);
				}
				return;
			}
			int num2 = ((array != null) ? array.Length : 0);
			int num3 = 0;
			int num4 = 0;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			for (int i = 0; i < num2; i++)
			{
				Collider val3 = array[i];
				if ((Object)(object)val3 == (Object)null)
				{
					continue;
				}
				EnemyAgent val4;
				try
				{
					val4 = ((Component)val3).GetComponentInParent<EnemyAgent>();
				}
				catch
				{
					val4 = null;
				}
				if ((Object)(object)val4 == (Object)null)
				{
					continue;
				}
				num3++;
				try
				{
					if (!((Component)val4).gameObject.activeInHierarchy)
					{
						num4++;
						continue;
					}
				}
				catch
				{
				}
				bool flag2;
				try
				{
					flag2 = val4.IsTagged;
				}
				catch
				{
					flag2 = false;
				}
				if (flag2)
				{
					num5++;
					continue;
				}
				if (!BioStickTracker.CfgTagShadows.Value)
				{
					bool flag3;
					try
					{
						flag3 = val4.IsInvisible();
					}
					catch
					{
						flag3 = false;
					}
					if (flag3)
					{
						num6++;
						continue;
					}
				}
				if (!BioStickTracker.CfgTagSleepers.Value && IsHibernating(val4))
				{
					num7++;
					continue;
				}
				ToolSyncManager.WantToTagEnemy(val4);
				num8++;
				if (!BioStickTracker.CfgDebugLog.Value)
				{
					continue;
				}
				int num9 = 0;
				try
				{
					num9 = ((Object)val4).GetInstanceID();
				}
				catch
				{
				}
				ManualLogSource logger3 = BioStickTracker.Logger;
				if (logger3 != null)
				{
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Glowstick] Tag request goId=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_goId);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" enemyId=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num9);
					}
					logger3.LogInfo(val);
				}
			}
			if (!BioStickTracker.CfgDebugLog.Value)
			{
				return;
			}
			ManualLogSource logger4 = BioStickTracker.Logger;
			if (logger4 != null)
			{
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(100, 8, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[Glowstick] Scan end goId=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_goId);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" cols=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" enemies=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num3);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("tagReq=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num8);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" skipInactive=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num4);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" skipTagged=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num5);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" skipShadow=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num6);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" skipSleeper=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num7);
				}
				logger4.LogInfo(val);
			}
		}

		private static bool IsHibernating(EnemyAgent enemy)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			if ((Object)(object)enemy == (Object)null)
			{
				return false;
			}
			EnemyLocomotion val = null;
			try
			{
				val = ((Component)enemy).GetComponent<EnemyLocomotion>();
			}
			catch
			{
				val = null;
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			try
			{
				return (int)val.CurrentStateEnum == 14;
			}
			catch
			{
				return false;
			}
		}
	}
}