using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppSystem.Collections.Generic;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("BotLikeBio")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BotLikeBio")]
[assembly: AssemblyTitle("BotLikeBio")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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 BotLikeBio
{
[BepInPlugin("plonne.gtfo.botlikebio", "BotLikeBio", "0.4.9")]
public sealed class Plugin : BasePlugin
{
[HarmonyPatch(typeof(EnemyScanner), "Setup")]
private static class EnemyScannerPatch
{
private static void Postfix(EnemyScanner __instance)
{
if (Enabled.Value && !((Object)(object)__instance == (Object)null))
{
ActiveScanner = __instance;
__instance.m_scanConeDotMin = -1f;
__instance.m_maxScanWorldRadius = MaxScanWorldRadius.Value;
__instance.m_maxObjs = MaxObjs.Value;
__instance.m_scanDelay = 0.05f;
__instance.m_pulseDuration = 0.05f;
__instance.m_posDelay = 0.05f;
__instance.m_rechargeDuration = RechargeDuration.Value;
EnemyScanner.s_maxCourseNodeDistance = MaxCourseNodeDistance.Value;
EnemyScanner.s_tagDuration = Mathf.Max(0.02f, ChargeTime.Value);
GameObject gameObject = ((Component)__instance).gameObject;
if ((Object)(object)gameObject.GetComponent<NativeScannerTagBridge>() == (Object)null)
{
gameObject.AddComponent<NativeScannerTagBridge>().Scanner = __instance;
}
}
}
}
[HarmonyPatch(typeof(EnemyScannerGraphics), "IsDetected")]
private static class EnemyScannerGraphicsIsDetectedPatch
{
private static void Postfix(EnemyAgent enemyAgent, ref bool __result)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
if (Enabled.Value && !((Object)(object)enemyAgent == (Object)null) && !((Object)(object)ActiveScanner == (Object)null) && !((Object)(object)((Item)ActiveScanner).Owner == (Object)null))
{
Vector3 position = ((Agent)((Item)ActiveScanner).Owner).Position;
Vector3 val = enemyAgent.Position - position;
float num = Mathf.Max(1f, DirectTagRange.Value);
if (((Vector3)(ref val)).sqrMagnitude <= num * num)
{
__result = true;
}
}
}
}
[HarmonyPatch(typeof(EnemyScanner), "Update")]
private static class EnemyScannerUpdatePatch
{
private static void Prefix(EnemyScanner __instance)
{
if (Enabled.Value && !((Object)(object)__instance == (Object)null))
{
EnemyScanner.s_tagDuration = Mathf.Max(0.02f, ChargeTime.Value);
__instance.m_rechargeDuration = RechargeDuration.Value;
}
}
}
public const string PluginGuid = "plonne.gtfo.botlikebio";
public const string PluginName = "BotLikeBio";
public const string PluginVersion = "0.4.9";
internal static ConfigEntry<bool> Enabled;
internal static ConfigEntry<float> DirectTagRange;
internal static ConfigEntry<float> ChargeTime;
internal static ConfigEntry<float> MaxScanWorldRadius;
internal static ConfigEntry<int> MaxObjs;
internal static ConfigEntry<int> MaxCourseNodeDistance;
internal static ConfigEntry<float> TagDuration;
internal static ConfigEntry<float> RechargeDuration;
internal static EnemyScanner? ActiveScanner;
public override void Load()
{
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Expected O, but got Unknown
Enabled = ((BasePlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable BotLikeBio.");
DirectTagRange = ((BasePlugin)this).Config.Bind<float>("BotLikeTagging", "DirectTagRange", 120f, "360-degree tag radius in metres.");
ChargeTime = ((BasePlugin)this).Config.Bind<float>("BotLikeTagging", "ChargeTime", 0.18f, "Native BioTracker charge/scan timing. Default 0.18 seconds.");
MaxScanWorldRadius = ((BasePlugin)this).Config.Bind<float>("Scanner", "MaxScanWorldRadius", 120f, "Native BioTracker radar/scan radius.");
MaxObjs = ((BasePlugin)this).Config.Bind<int>("Scanner", "MaxObjs", 20, "Maximum scanner objects.");
MaxCourseNodeDistance = ((BasePlugin)this).Config.Bind<int>("Scanner", "MaxCourseNodeDistance", 8, "Maximum course-node distance.");
TagDuration = ((BasePlugin)this).Config.Bind<float>("Scanner", "TagDuration", 2f, "Legacy setting retained for config compatibility; native hold now follows ChargeTime.");
RechargeDuration = ((BasePlugin)this).Config.Bind<float>("Scanner", "RechargeDuration", 0.1f, "Native BioTracker recharge duration.");
ClassInjector.RegisterTypeInIl2Cpp<NativeScannerTagBridge>();
new Harmony("plonne.gtfo.botlikebio").PatchAll(typeof(Plugin).Assembly);
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(9, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("BotLikeBio");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("0.4.9");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded.");
}
log.LogInfo(val);
}
}
public sealed class NativeScannerTagBridge : MonoBehaviour
{
public EnemyScanner Scanner;
private bool _wasRecharging;
public NativeScannerTagBridge(IntPtr ptr)
: base(ptr)
{
}
private void Awake()
{
if ((Object)(object)Scanner == (Object)null)
{
Scanner = ((Component)this).GetComponent<EnemyScanner>();
}
}
private void FixedUpdate()
{
if (Plugin.Enabled.Value && !((Object)(object)Scanner == (Object)null))
{
bool recharging = Scanner.m_recharging;
if (!_wasRecharging && recharging)
{
TagEverythingInRange();
}
_wasRecharging = recharging;
}
}
private void TagEverythingInRange()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Expected I4, but got Unknown
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)Builder.CurrentFloor == (Object)null || (Object)(object)((Item)Scanner).Owner == (Object)null)
{
return;
}
Vector3 position = ((Agent)((Item)Scanner).Owner).Position;
float num = Mathf.Max(1f, Plugin.DirectTagRange.Value);
float num2 = num * num;
Enumerator<LG_Zone> enumerator = Builder.CurrentFloor.allZones.GetEnumerator();
while (enumerator.MoveNext())
{
Enumerator<LG_Area> enumerator2 = enumerator.Current.m_areas.GetEnumerator();
while (enumerator2.MoveNext())
{
LG_Area current = enumerator2.Current;
if ((Object)(object)current == (Object)null || current.m_courseNode == null)
{
continue;
}
Enumerator<EnemyAgent> enumerator3 = current.m_courseNode.m_enemiesInNode.GetEnumerator();
while (enumerator3.MoveNext())
{
EnemyAgent current2 = enumerator3.Current;
if ((Object)(object)current2 == (Object)null || (Object)(object)current2.AI == (Object)null)
{
continue;
}
int num3 = (int)((AgentAI)current2.AI).Mode;
if (num3 == 1 || num3 == 2 || num3 == 3)
{
Vector3 val = current2.Position - position;
if (!(((Vector3)(ref val)).sqrMagnitude > num2))
{
ToolSyncManager.WantToTagEnemy(current2);
}
}
}
}
}
}
}
}