using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SpawnedEnemiesFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpawnedEnemiesFix")]
[assembly: AssemblyTitle("SpawnedEnemiesFix")]
[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 SpawnedEnemiesFix
{
[BepInPlugin("dejay.SpawnedEnemiesFix", "SpawnedEnemiesFix", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class SpawnedEnemiesFixPlugin : BaseUnityPlugin
{
private readonly Harmony harmony = new Harmony("dejay.SpawnedEnemiesFix");
internal static ManualLogSource Log;
private void Awake()
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00ad: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Type type = null;
Assembly[] array = assemblies;
for (int i = 0; i < array.Length; i++)
{
type = array[i].GetType("ControlCompany.Core.ControlCenter");
if (type != null)
{
break;
}
}
if (type == null)
{
Log.LogError((object)"SpawnedEnemiesFix: Could not find ControlCenter type! Is ControlCompany installed?");
return;
}
MethodInfo method = type.GetMethod("SpawnControllableEnemy", BindingFlags.Instance | BindingFlags.NonPublic);
if (method == null)
{
Log.LogError((object)"SpawnedEnemiesFix: Could not find SpawnControllableEnemy method!");
return;
}
MethodInfo method2 = typeof(SpawnControllableEnemyPatch).GetMethod("Postfix");
harmony.Patch((MethodBase)method, (HarmonyMethod)null, new HarmonyMethod(method2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
Log.LogInfo((object)"SpawnedEnemiesFix loaded and patched successfully!");
}
}
public static class SpawnControllableEnemyPatch
{
private static FieldInfo? FindFieldInHierarchy(Type type, string fieldName)
{
Type type2 = type;
while (type2 != null)
{
FieldInfo field = type2.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (field != null)
{
return field;
}
type2 = type2.BaseType;
}
return null;
}
public static void Postfix(object __result)
{
if (__result == null)
{
SpawnedEnemiesFixPlugin.Log.LogWarning((object)"SpawnedEnemiesFix: __result is null.");
return;
}
SpawnedEnemiesFixPlugin.Log.LogInfo((object)("SpawnedEnemiesFix: __result type = " + __result.GetType().FullName));
if ((Object)(object)RoundManager.Instance == (Object)null)
{
SpawnedEnemiesFixPlugin.Log.LogWarning((object)"SpawnedEnemiesFix: RoundManager.Instance is null, skipping.");
return;
}
EnemyAI val = null;
FieldInfo fieldInfo = FindFieldInHierarchy(__result.GetType(), "enemyAI");
if (fieldInfo != null)
{
object? value = fieldInfo.GetValue(__result);
val = (EnemyAI)((value is EnemyAI) ? value : null);
if ((Object)(object)val != (Object)null)
{
SpawnedEnemiesFixPlugin.Log.LogInfo((object)"SpawnedEnemiesFix: Found EnemyAI via field 'enemyAI' in hierarchy.");
}
}
if ((Object)(object)val == (Object)null)
{
MonoBehaviour val2 = (MonoBehaviour)((__result is MonoBehaviour) ? __result : null);
if (val2 != null)
{
val = ((Component)val2).GetComponent<EnemyAI>();
if ((Object)(object)val == (Object)null)
{
val = ((Component)val2).GetComponentInChildren<EnemyAI>(true);
}
if ((Object)(object)val == (Object)null)
{
val = ((Component)val2).GetComponentInParent<EnemyAI>();
}
}
}
if ((Object)(object)val == (Object)null)
{
SpawnedEnemiesFixPlugin.Log.LogWarning((object)("SpawnedEnemiesFix: Could not find EnemyAI on " + __result.GetType().FullName + ", skipping."));
}
else if (!RoundManager.Instance.SpawnedEnemies.Contains(val))
{
RoundManager.Instance.SpawnedEnemies.Add(val);
SpawnedEnemiesFixPlugin.Log.LogInfo((object)("SpawnedEnemiesFix: Added " + val.enemyType?.enemyName + " to SpawnedEnemies."));
}
}
}
}