Decompiled source of BioWeapons v0.2.3

BioWeapons.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using GTFO.API;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
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("BioWeapons")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+b0afd1683b6eb6bc434edee97708d3b5028f53ae")]
[assembly: AssemblyProduct("BioWeapons")]
[assembly: AssemblyTitle("BioWeapons")]
[assembly: AssemblyVersion("1.0.0.0")]
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 BioWeapons
{
	internal static class ConfigMgr
	{
		public static ConfigFile conf;

		private static ConfigEntry<bool> _debug;

		public static bool DEBUG => _debug.Value;

		static ConfigMgr()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			string text = Path.Combine(Paths.ConfigPath, "BioWeapons.cfg");
			Logger.Info("cfgPath = " + text);
			conf = new ConfigFile(text, true);
			int num = 1;
			string text2 = $"({num++}) BioWeapons";
			text2 = "(Z) Dev";
			_debug = conf.Bind<bool>(text2, "Debug Logging", false, "Whether to enable debug logging");
		}
	}
	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)
		{
			if (ConfigMgr.DEBUG)
			{
				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));
		}

		public static void Chat(object msg)
		{
			PlayerChatManager.PostChatMessageLocaly(SNet.LocalPlayer, (string)msg, (SNet_Player)null);
		}
	}
	[HarmonyPatch]
	internal class Patch
	{
		public static WeaponBioManager? Wpm;

		[HarmonyPatch(typeof(BulletWeapon), "BulletHit")]
		[HarmonyPostfix]
		private static void BulletHit(bool __result, WeaponHitData weaponRayData, bool doDamage)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			if (!__result || !doDamage || !Wpm.EnableForBullets || !Wpm.CanTagEnemy())
			{
				return;
			}
			PlayerAgent owner = weaponRayData.owner;
			if ((Object)(object)owner == (Object)null || !((Agent)owner).IsLocallyOwned)
			{
				return;
			}
			RaycastHit rayHit = weaponRayData.rayHit;
			object obj;
			if (!Object.op_Implicit((Object)(object)((RaycastHit)(ref rayHit)).collider))
			{
				obj = null;
			}
			else
			{
				rayHit = weaponRayData.rayHit;
				obj = ((Component)((RaycastHit)(ref rayHit)).collider).gameObject;
			}
			GameObject val = (GameObject)obj;
			if (!((Object)(object)val == (Object)null))
			{
				EnemyAgent componentInParent = val.GetComponentInParent<EnemyAgent>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					ToolSyncManager.WantToTagEnemy(componentInParent);
				}
			}
		}

		[HarmonyPatch(typeof(MeleeWeaponFirstPerson), "DoAttackDamage")]
		[HarmonyPostfix]
		private static void DoAttackDamage(MeleeWeaponFirstPerson __instance, MeleeWeaponDamageData data, bool isPush)
		{
			if (!Wpm.EnableForMelee || !Wpm.CanTagEnemy())
			{
				return;
			}
			PlayerAgent val = ((__instance != null) ? ((Item)__instance).Owner : null);
			if ((Object)(object)val == (Object)null || !((Agent)val).IsLocallyOwned)
			{
				return;
			}
			GameObject val2 = ((data != null) ? data.damageGO : null);
			if (!((Object)(object)val2 == (Object)null))
			{
				EnemyAgent componentInParent = val2.GetComponentInParent<EnemyAgent>();
				if (!((Object)(object)componentInParent == (Object)null))
				{
					ToolSyncManager.WantToTagEnemy(componentInParent);
				}
			}
		}
	}
	[BepInPlugin("io.takina.gtfo.BioWeapons", "BioWeapons", "0.2.3")]
	public class Plugin : BasePlugin
	{
		public const string NAME = "BioWeapons";

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

		public const string VERSION = "0.2.3";

		public override void Load()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			Logger.SetupFromInit(((BasePlugin)this).Log);
			Logger.Info("BioWeapons io.takina.gtfo.BioWeapons 0.2.3");
			Logger.Info("Patching...");
			Logger.Info("DEBUG = " + ConfigMgr.DEBUG);
			ClassInjector.RegisterTypeInIl2Cpp<WeaponBioManager>();
			GameObject val = new GameObject("BioWeapons");
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<WeaponBioManager>();
			EventAPI.OnAssetsLoaded += delegate
			{
				Patch.Wpm = WeaponBioManager.Instance;
			};
			Harmony.CreateAndPatchAll(typeof(Patch), "io.takina.gtfo.BioWeapons");
			Logger.Info("Finished Patching");
		}
	}
	public class WeaponBioManager : MonoBehaviour
	{
		internal bool EnableForMelee = true;

		internal bool EnableForBullets = true;

		public const float TAG_COOLDOWN = 3f;

		private float _lastTagTime = 0f;

		private bool _enableCooldown = true;

		public static WeaponBioManager? Instance { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
				Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void Update()
		{
			bool flag = false;
			if (Input.GetKeyDown((KeyCode)289))
			{
				EnableForMelee = !EnableForMelee;
				Logger.Info($"EnableForMelee toggled, is now = \"{EnableForMelee}\"");
				flag = true;
			}
			if (Input.GetKeyDown((KeyCode)290))
			{
				EnableForBullets = !EnableForBullets;
				Logger.Info($"EnableForBullets toggled, is now = \"{EnableForBullets}\"");
				flag = true;
			}
			bool flag2 = false;
			if (flag)
			{
				Logger.Chat($"[BioWeapons] Melee: {Bool2OnOff(EnableForMelee)} | Bullets: {Bool2OnOff(EnableForBullets)}");
			}
		}

		private string Bool2OnOff(bool status)
		{
			return status ? "<#0F0>ON</color>" : "<#F00>OFF</color>";
		}

		public bool CanTagEnemy()
		{
			if (!_enableCooldown)
			{
				return true;
			}
			if (Time.time - _lastTagTime < 3f)
			{
				return false;
			}
			_lastTagTime = Time.time;
			return true;
		}
	}
}