Decompiled source of BiotrackerExplode v1.1.0

plugins/GTFO_BiotrackerExplode.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AK;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GTFO.API;
using GTFO.API.Utilities;
using Gear;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyFileVersion("1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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;
		}
	}
}
internal class ManifestInfo
{
	internal const string TSName = "BiotrackerExplode";

	internal const string TSDescription = "Causes the biotracker to maybe explode. Make sure your biotracking is on point!";

	internal const string TSVersion = "1.1.0";

	internal const string TSAuthor = "Giginss";

	internal const string TSWebsite = "https://github.com/GreatWyrm/BiotrackerExplodes";
}
namespace BiotrackerExplode
{
	[HarmonyPatch]
	public class BiotrackerPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyScanner), "UpdateTagProgress")]
		public static void Postfix(EnemyScanner __instance, int maxTags)
		{
			if (__instance.m_lastTagging && !__instance.m_tagging && !__instance.m_lastRecharging && __instance.m_recharging)
			{
				Plugin.EvaluatePings(__instance.m_taggableEnemies);
			}
		}
	}
	public class Networking
	{
		private static CellSoundPlayer soundPlayer;

		private static readonly string NetworkEvent = "BiotrackerExplode";

		public static void Init()
		{
			NetworkAPI.RegisterEvent<Vector3>(NetworkEvent, (Action<ulong, Vector3>)OnExplosionReceive);
			LevelAPI.OnEnterLevel += SetupCellSound;
		}

		public static void SetupCellSound()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			if (soundPlayer == null)
			{
				soundPlayer = new CellSoundPlayer();
			}
		}

		public static void BroadcastAndPlayToSelf(Vector3 position)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			NetworkAPI.InvokeEvent<Vector3>(NetworkEvent, position, (SNet_ChannelType)2);
			soundPlayer.Post(EVENTS.STICKYMINEEXPLODE, position);
		}

		public static void OnExplosionReceive(ulong id, Vector3 position)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			soundPlayer.Post(EVENTS.STICKYMINEEXPLODE, position);
		}
	}
	[BepInPlugin("dev.Giginss.gtfo.BiotrackerExplode", "BiotrackerExplode", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string GUID = "dev.Giginss.gtfo.BiotrackerExplode";

		public const string MOD_NAME = "BiotrackerExplode";

		public const string VERSION = "1.1.0";

		internal static ManualLogSource L;

		private static readonly Harmony _harmony = new Harmony("dev.Giginss.gtfo.BiotrackerExplode");

		private static Random _random = new Random();

		public override void Load()
		{
			L = ((BasePlugin)this).Log;
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
			Networking.Init();
			PluginConfig.Init();
			L.LogInfo((object)"Exploding biotracker loaded!");
		}

		public static void EvaluatePings(List<EnemyAgent> enemies)
		{
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			L.LogDebug((object)"Evaluating biotracker pings");
			PluginConfig.ConfigSettings config = PluginConfig.GetConfig();
			int count = enemies.Count;
			int num = 0;
			for (int i = 0; i < enemies.Count; i++)
			{
				if (enemies[i].IsScout && !config.includeScouts)
				{
					num++;
				}
				if (enemies[i].EnemyDataID == 29 && !config.includeTanks)
				{
					num++;
				}
				if (enemies[i].EnemyDataID == 47 && !config.includePablo)
				{
					num++;
				}
			}
			count -= num;
			if (count <= 0 || (double)count > config.threshold)
			{
				return;
			}
			L.LogDebug((object)"Below threshold!");
			if (!(_random.NextDouble() < config.chance))
			{
				return;
			}
			L.LogDebug((object)"Rolled chance, exploding!");
			PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
			if (!((Object)(object)localPlayerAgent == (Object)null))
			{
				Networking.BroadcastAndPlayToSelf(((Agent)localPlayerAgent).m_position);
				if (config.isLethal)
				{
					localPlayerAgent.Damage.OnIncomingDamage(((Dam_SyncedDamageBase)localPlayerAgent.Damage).Health + 1f, ((Dam_SyncedDamageBase)localPlayerAgent.Damage).Health + 1f, (Agent)null);
				}
			}
		}
	}
	public class PluginConfig
	{
		public struct ConfigSettings
		{
			public double chance;

			public double threshold;

			public bool includeScouts;

			public bool isLethal;

			public bool includeTanks;

			public bool includePablo;
		}

		private static ConfigFile ConfigFile;

		private static ConfigEntry<double> explodeChance;

		private static ConfigEntry<int> explodeThreshold;

		private static ConfigEntry<bool> includeScouts;

		private static ConfigEntry<bool> willExplodeSelf;

		private static ConfigEntry<bool> includeTanks;

		private static ConfigEntry<bool> includePablo;

		public static void Init()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			ConfigFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "BiotrackerExplode.cfg"), true);
			explodeChance = ConfigFile.Bind<double>("Exploding Biotracker", "ExplosionChance", 0.05, "The chance for the biotracker to explode when you don't get above the threshold");
			explodeThreshold = ConfigFile.Bind<int>("Exploding Biotracker", "ExplosionThreshold", 1, "The amount of enemies to be equal to or below for the chance to explode to be rolled");
			includeScouts = ConfigFile.Bind<bool>("Exploding Biotracker", "IncludeScouts", false, "Whether or not to include scouts when tallying the amount of enemies that were pinged.");
			willExplodeSelf = ConfigFile.Bind<bool>("Exploding Biotracker", "IsLethal", true, "Whether or not exploding will kill the player using the biotracker");
			includeTanks = ConfigFile.Bind<bool>("Exploding Biotracker", "IncludeTanks", true, "Whether or not to include tanks when tallying the amount of enemies");
			includePablo = ConfigFile.Bind<bool>("Exploding Biotracker", "IncludeImmortal", false, "Whether or not to include the Immortal/Pablo when tallying the amount of enemies");
			SafeFileSystemWatcher.Create(ConfigFile);
		}

		public static ConfigSettings GetConfig()
		{
			return new ConfigSettings
			{
				chance = explodeChance.Value,
				threshold = explodeThreshold.Value,
				includeScouts = includeScouts.Value,
				includeTanks = includeTanks.Value,
				includePablo = includePablo.Value,
				isLethal = willExplodeSelf.Value
			};
		}
	}
}