using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
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 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")]
[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 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
{
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.1.0")]
public class Plugin : BasePlugin
{
public const string NAME = "BioWeapons";
public const string GUID = "io.takina.gtfo.BioWeapons";
public const string VERSION = "0.1.0";
public override void Load()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Expected O, but got Unknown
Logger.SetupFromInit(((BasePlugin)this).Log);
Logger.Info("BioWeapons io.takina.gtfo.BioWeapons 0.1.0");
Logger.Info("Patching...");
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()
{
if (Input.GetKeyDown((KeyCode)289))
{
EnableForMelee = !EnableForMelee;
Logger.Info($"EnableForMelee toggled, is now = \"{EnableForMelee}\"");
}
if (Input.GetKeyDown((KeyCode)290))
{
EnableForBullets = !EnableForBullets;
Logger.Info($"EnableForBullets toggled, is now = \"{EnableForBullets}\"");
}
if (Input.GetKeyDown((KeyCode)291))
{
_enableCooldown = !_enableCooldown;
Logger.Info($"EnableCooldown toggled, is now = \"{_enableCooldown}\"");
}
}
public bool CanTagEnemy()
{
if (!_enableCooldown)
{
return true;
}
if (Time.time - _lastTagTime < 3f)
{
return false;
}
_lastTagTime = Time.time;
return true;
}
}
}