Decompiled source of BiotrackerEnemyCount v0.2.1

BiotrackerEnemyCount.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem.Collections.Generic;
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 = "")]
[assembly: AssemblyCompany("BiotrackerEnemyCount")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BiotrackerEnemyCount")]
[assembly: AssemblyTitle("BiotrackerEnemyCount")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace BioCount
{
	internal static class Logger
	{
		private static ManualLogSource m_LogSource;

		public static void SetupFromInit(ManualLogSource logSource)
		{
			m_LogSource = logSource;
		}

		private static string Format(object data)
		{
			return data.ToString();
		}

		public static void Debug(object msg)
		{
			bool flag = true;
			m_LogSource.LogInfo((object)Format(msg));
		}

		public static void Info(object msg)
		{
			m_LogSource.LogInfo((object)Format(msg));
		}

		public static void Warn(object msg)
		{
			m_LogSource.LogWarning((object)Format(msg));
		}

		public static void Error(object msg)
		{
			m_LogSource.LogError((object)Format(msg));
		}

		public static void Fatal(object msg)
		{
			m_LogSource.LogFatal((object)Format(msg));
		}
	}
	[HarmonyPatch]
	internal class Patch
	{
		[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
		public delegate bool TryGetTaggableEnemiesDel(IntPtr thisPtr, int maxTags, bool isOnAim, out IntPtr enemies);

		public static TryGetTaggableEnemiesDel ScannerMethod;

		[HarmonyPatch(typeof(EnemyScanner), "UpdateTagProgress")]
		[HarmonyPostfix]
		public static void Update(EnemyScanner __instance, int maxTags)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				IntPtr enemies;
				bool flag = ScannerMethod(((Il2CppObjectBase)__instance).Pointer, maxTags, isOnAim: true, out enemies);
				List<EnemyAgent> val = new List<EnemyAgent>(enemies);
				int num = ((__instance.m_enemiesDetected != null) ? __instance.m_enemiesDetected.Count : 0);
				int count = val.Count;
				int num2 = num - count;
				__instance.m_screen.SetNoTargetsText(count + ":" + num2 + "/" + num);
			}
		}
	}
	[BepInPlugin("io.takina.gtfo.BioCount", "BioCount", "0.2.1")]
	public class Plugin : BasePlugin
	{
		public const string NAME = "BioCount";

		public const string GUID = "io.takina.gtfo.BioCount";

		public const string VERSION = "0.2.1";

		public unsafe static void PlugInit()
		{
			IntPtr nativeClassPtr = Il2CppClassPointerStore<EnemyScanner>.NativeClassPtr;
			void** ptr = (void**)IL2CPP.GetIl2CppMethod(nativeClassPtr, false, "TryGetTaggableEnemies", typeof(bool).FullName, new string[2]
			{
				typeof(int).FullName,
				typeof(bool).FullName
			}).ToPointer();
			IntPtr intPtr = (IntPtr)((ptr == null) ? ptr : (*ptr));
			if (intPtr == IntPtr.Zero)
			{
				Logger.Debug("Its fucked gg go Next!");
			}
			else
			{
				Patch.ScannerMethod = Marshal.GetDelegateForFunctionPointer<Patch.TryGetTaggableEnemiesDel>(intPtr);
			}
		}

		public override void Load()
		{
			Logger.SetupFromInit(((BasePlugin)this).Log);
			Logger.Info("BioCount io.takina.gtfo.BioCount 0.2.1");
			Logger.Info("Patching...");
			PlugInit();
			Harmony.CreateAndPatchAll(typeof(Patch), "io.takina.gtfo.BioCount");
			Logger.Info("Finished Patching");
		}
	}
}