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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("StuckEnemyFix")]
[assembly: AssemblyConfiguration("Debug")]
[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.7")]
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 = 0;
private void Awake()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: 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_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Invalid comparison between Unknown and I4
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Invalid comparison between Unknown and I4
//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Invalid comparison between Unknown and I4
//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_0193: Expected O, but got Unknown
//IL_0215: Unknown result type (might be due to invalid IL or missing references)
//IL_021a: Unknown result type (might be due to invalid IL or missing references)
//IL_0324: Unknown result type (might be due to invalid IL or missing references)
//IL_0329: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Unknown result type (might be due to invalid IL or missing references)
//IL_0349: Unknown result type (might be due to invalid IL or missing references)
//IL_037e: Unknown result type (might be due to invalid IL or missing references)
//IL_038a: Unknown result type (might be due to invalid IL or missing references)
//IL_038c: Unknown result type (might be due to invalid IL or missing references)
//IL_0287: Unknown result type (might be due to invalid IL or missing references)
//IL_02d0: 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 ((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 < 30f)
{
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 > 60f)
{
done = true;
}
else if (((Agent)enemy).Alive && Vector3.Distance(startpos, enemy.Position) < 2f)
{
ManualLogSource l = L;
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);
PlayerAgent target = default(PlayerAgent);
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;
}
else 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++;
}
else
{
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;
((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)
{
StuckWatcher component = ((Component)__instance.m_spawnedEnemyAgent).gameObject.GetComponent<StuckWatcher>();
if ((Object)(object)component == (Object)null)
{
((Component)__instance.m_spawnedEnemyAgent).gameObject.AddComponent<StuckWatcher>();
}
}
}
}
internal static ManualLogSource L;
public override void Load()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
L = ((BasePlugin)this).Log;
ClassInjector.RegisterTypeInIl2Cpp<StuckWatcher>();
Harmony val = new Harmony("StuckEnemyFix");
val.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;
}
}