using System;
using System.CodeDom.Compiler;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AIGraph;
using Agents;
using BepInEx;
using BepInEx.Unity.IL2CPP;
using Enemies;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("StuckEnemyFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StuckEnemyFix")]
[assembly: AssemblyTitle("StuckEnemyFix")]
[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 StuckEnemyFix
{
[BepInPlugin("StuckEnemyFix", "StuckEnemyFix", "0.0.4")]
public class Plugin : BasePlugin
{
private class StuckWatcher : MonoBehaviour
{
private Vector3 startpos;
private float spawntime;
private EnemyAgent enemy;
private bool done;
private AIG_CourseNode spawnnode;
private int count;
private void Awake()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
spawntime = Clock.Time;
enemy = ((Component)this).GetComponent<EnemyAgent>();
startpos = enemy.Position;
spawnnode = enemy.m_courseNode;
}
private void FixedUpdate()
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Invalid comparison between Unknown and I4
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Invalid comparison between Unknown and I4
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Invalid comparison between Unknown and I4
//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_023f: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_0272: Unknown result type (might be due to invalid IL or missing references)
//IL_0273: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)enemy == (Object)null || done)
{
return;
}
if ((int)((AgentAI)enemy.AI).Mode == 4)
{
done = true;
}
else if (!((Agent)enemy).Alive)
{
done = true;
}
else if ((int)enemy.Locomotion.CurrentStateEnum == 17)
{
spawntime = Clock.Time;
}
else
{
if (Clock.Time - spawntime < 6f)
{
return;
}
if ((int)((AgentAI)enemy.AI).Mode != 1)
{
done = true;
}
else if (((Agent)enemy).Alive && Vector3.Distance(startpos, enemy.Position) > 2f)
{
done = true;
}
else if (Clock.Time - spawntime > 12f)
{
done = true;
}
else if (((Agent)enemy).Alive && Vector3.Distance(startpos, enemy.Position) < 2f)
{
Debug.Log(Object.op_Implicit($"StuckEnemyFix - enemy {((Agent)enemy).GlobalID} stuck in spawn position for 6+ seconds, unstucking, count {count} .."));
if (count > 3)
{
enemy.Damage.MeleeDamage(((Dam_SyncedDamageBase)enemy.Damage).DamageMax, (Agent)null, Vector3.zero, Vector3.zero, 0, 1f, 1f, 1f, 1f, false, (DamageNoiseLevel)0, 0u);
done = true;
return;
}
if (count > 0)
{
((AgentAI)enemy.AI).m_navMeshAgent.SetDestination(((Agent)PlayerManager.GetLocalPlayerAgent()).Position);
spawntime = Clock.Time;
count++;
return;
}
count++;
((AgentAI)enemy.AI).m_navMeshAgent.enabled = false;
Vector3 randomPositionInside = spawnnode.GetRandomPositionInside();
enemy.Position = randomPositionInside;
((Component)enemy).gameObject.transform.position = randomPositionInside;
((AgentAI)enemy.AI).m_navMeshAgent.enabled = true;
startpos = randomPositionInside;
spawntime = Clock.Time;
}
}
}
}
[HarmonyPatch]
private class StuckEnemyFixPatches
{
[HarmonyPatch(typeof(EnemyAllocator), "OnEnemySpawned")]
[HarmonyPostfix]
private static void Postfix(EnemyAllocator __instance)
{
if (!__instance.m_spawnedEnemyAgent.EnemyBehaviorData.IsFlyer)
{
((Component)__instance.m_spawnedEnemyAgent).gameObject.AddComponent<StuckWatcher>();
}
}
}
public override void Load()
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
ClassInjector.RegisterTypeInIl2Cpp<StuckWatcher>();
new Harmony("StuckEnemyFix").PatchAll();
}
}
[GeneratedCode("VersionInfoGenerator", "2.0.0+git50a4b1a-master")]
[CompilerGenerated]
internal static class VersionInfo
{
public const string RootNamespace = "StuckEnemyFix";
public const string Version = "1.0.0";
public const string VersionPrerelease = null;
public const string VersionMetadata = null;
public const string SemVer = "1.0.0";
public const string GitRevShort = null;
public const string GitRevLong = null;
public const string GitBranch = null;
public const string GitTag = null;
public const bool GitIsDirty = false;
}
}