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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Enemies;
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.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.8")]
internal class Plugin : BasePlugin
{
private class StuckWatcher : MonoBehaviour
{
private Vector3 startpos;
private float spawntime;
private EnemyAgent? enemy;
private bool spawndone;
private bool done;
private AIG_CourseNode? spawnnode;
private int count;
private void Awake()
{
spawntime = Clock.Time;
enemy = ((Component)this).GetComponent<EnemyAgent>();
}
private void FixedUpdate()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Invalid comparison between Unknown and I4
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Invalid comparison between Unknown and I4
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Invalid comparison between Unknown and I4
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0104: Unknown result type (might be due to invalid IL or missing references)
//IL_0149: Unknown result type (might be due to invalid IL or missing references)
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Expected O, but got Unknown
//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0310: Unknown result type (might be due to invalid IL or missing references)
//IL_0326: Unknown result type (might be due to invalid IL or missing references)
//IL_0358: Unknown result type (might be due to invalid IL or missing references)
//IL_0363: Unknown result type (might be due to invalid IL or missing references)
//IL_0364: Unknown result type (might be due to invalid IL or missing references)
//IL_0304: Unknown result type (might be due to invalid IL or missing references)
//IL_0309: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: Unknown result type (might be due to invalid IL or missing references)
//IL_0297: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)enemy == (Object)null)
{
return;
}
if (done)
{
((Behaviour)this).enabled = false;
}
else if (!((Agent)enemy).Alive)
{
done = true;
}
else if ((int)((AgentAI)enemy.AI).Mode != 1)
{
done = true;
}
else
{
if (!spawndone && Clock.Time - spawntime < 1f)
{
return;
}
if (!spawndone)
{
spawndone = true;
startpos = enemy.Position;
spawnnode = enemy.m_courseNode;
}
if ((int)enemy.Locomotion.CurrentStateEnum == 17)
{
spawntime = Clock.Time;
}
else if ((int)((AgentAI)enemy.AI).Mode == 4)
{
done = true;
}
else
{
if (Clock.Time - spawntime < 30f)
{
return;
}
if (((Agent)enemy).Alive && Vector3.Distance(startpos, enemy.Position) > 2f)
{
done = true;
}
else if (Clock.Time - spawntime > 160f)
{
done = true;
}
else
{
if (!((Agent)enemy).Alive || !(Vector3.Distance(startpos, enemy.Position) < 2f))
{
return;
}
ManualLogSource l = L;
if (l != null)
{
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(69, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("enemy ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<ushort>(((Agent)enemy).GlobalID);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" stuck in spawn position for 30+ seconds, unstucking, count ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ..");
}
l.LogInfo(val);
}
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;
}
PlayerAgent target = default(PlayerAgent);
if (count > 0 && PlayerManager.TryGetClosestAlivePlayerAgent(((Agent)enemy).CourseNode, ref target))
{
((AgentAI)enemy.AI).m_navMeshAgent.Warp(enemy.Position);
((AgentAI)enemy.AI).m_navMeshAgent.ResetPath();
((AgentAI)enemy.AI).SetTarget((Agent)(object)target);
((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 = default(Vector3);
((Vector3)(ref randomPositionInside))..ctor(0f, 0f, 20f);
if (spawnnode != null)
{
randomPositionInside = spawnnode.GetRandomPositionInside();
}
enemy.Position = randomPositionInside;
((Component)enemy).gameObject.transform.position = randomPositionInside;
((AgentAI)enemy.AI).m_navMeshAgent.enabled = true;
((AgentAI)enemy.AI).m_navMeshAgent.Warp(enemy.Position);
startpos = randomPositionInside;
spawntime = Clock.Time;
}
}
}
}
}
[HarmonyPatch]
private class StuckEnemyFixPatches
{
[HarmonyPatch(typeof(EnemyAllocator), "SpawnEnemy")]
[HarmonyPostfix]
private static void Postfix(EnemyAllocator __instance)
{
if (SNet.IsMaster && !__instance.m_spawnedEnemyAgent.EnemyBehaviorData.IsFlyer && (Object)(object)((Component)__instance.m_spawnedEnemyAgent).gameObject.GetComponent<StuckWatcher>() == (Object)null)
{
((Component)__instance.m_spawnedEnemyAgent).gameObject.AddComponent<StuckWatcher>();
}
}
}
internal static ManualLogSource? L;
public override void Load()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
L = ((BasePlugin)this).Log;
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;
}
}