using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Fandovec03")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Personal Library with functions for getting, sorting and filtering enemies")]
[assembly: AssemblyFileVersion("0.6.5.0")]
[assembly: AssemblyInformationalVersion("0.6.5+95e2b6e3894a98d64d10aff3c33abf8391666cbf")]
[assembly: AssemblyProduct("NaturalSelectionLib")]
[assembly: AssemblyTitle("fandovec03.NaturalSelectionLib")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/Fandovec03/NaturalSelectionLib.git")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.5.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace NaturalSelectionLib
{
[BepInPlugin("fandovec03.NaturalSelectionLib", "NaturalSelectionLib", "0.6.5")]
public class NaturalSelectionLib : BaseUnityPlugin
{
public static bool debugLibrary = false;
public static bool debugSpam = false;
public static ManualLogSource LibraryLogger = new ManualLogSource("NaturalSelectionLib");
public static Dictionary<Type, List<EnemyAI>> globalEnemyLists = new Dictionary<Type, List<EnemyAI>>();
public static void UpdateListInsideDictionrary(Type instanceType, List<EnemyAI> list)
{
List<Type> list2 = new List<Type>();
if (!globalEnemyLists.ContainsKey(instanceType))
{
globalEnemyLists.Add(instanceType, new List<EnemyAI>(list));
if (debugSpam && debugLibrary)
{
LibraryLogger.LogInfo((object)("/updateListInsideDictionary/ created new list for " + instanceType));
}
}
else
{
globalEnemyLists[instanceType] = new List<EnemyAI>(list);
if (debugSpam && debugLibrary)
{
LibraryLogger.LogInfo((object)("/updateListInsideDictionary/ updating list for " + instanceType));
}
}
if (!list2.Contains(instanceType))
{
list2.Add(instanceType);
}
}
public static void LibrarySetup(ManualLogSource importLogger, bool spammyLogs = false, bool debuglibrary = false)
{
LibraryLogger = importLogger;
debugSpam = spammyLogs;
debugLibrary = debuglibrary;
}
public static string DebugStringHead(EnemyAI? __instance)
{
if (!Object.op_Implicit((Object)(object)__instance))
{
return "Unknown instance: ";
}
return ((__instance != null) ? ((Object)__instance).name : null) + " ID: " + ((__instance != null) ? new ulong?(((NetworkBehaviour)__instance).NetworkObjectId) : null) + ": ";
}
public static List<EnemyAI> GetCompleteList(EnemyAI instance, bool filterThemselves = true, int includeOrReturnTheDead = 0)
{
List<EnemyAI> list = new List<EnemyAI>(RoundManager.Instance.SpawnedEnemies);
for (int i = 0; i < list.Count; i++)
{
if ((Object)(object)list[i] == (Object)(object)instance)
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + " Found itself in the list. Removing..."));
}
list.Remove(list[i]);
}
else if (((object)list[i]).GetType() == ((object)instance).GetType() && filterThemselves)
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + " Found its type in the list. Removing..."));
}
list.Remove(list[i]);
}
else
{
if (!list[i].isEnemyDead)
{
continue;
}
switch (includeOrReturnTheDead)
{
case 0:
if (debugLibrary && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + " Found dead enemy in the list. Removing..."));
}
list.Remove(list[i]);
break;
case 1:
if (debugLibrary && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + " Found dead enemy in the list. Proceeding..."));
}
break;
case 2:
if (debugLibrary && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + " Found living enemy in the list. Removing.."));
}
list.Remove(list[i]);
break;
}
}
}
return list;
}
public static List<EnemyAI> GetInsideOrOutsideEnemyList(List<EnemyAI> importEnemyList, EnemyAI instance)
{
List<EnemyAI> list = new List<EnemyAI>();
foreach (EnemyAI importEnemy in importEnemyList)
{
if ((Object)(object)importEnemy != (Object)(object)instance && ((importEnemy.isOutside && instance.isOutside) || (!importEnemy.isOutside && !instance.isOutside)))
{
list.Add(importEnemy);
if (debugLibrary && debugSpam)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + "/GetInsideOrOutsideEnemyList/ addded " + DebugStringHead(importEnemy) + "..."));
}
}
}
return list;
}
public static EnemyAI? FindClosestEnemy(List<EnemyAI> importEnemyList, EnemyAI? importClosestEnemy, EnemyAI __instance, bool includeTheDead = false)
{
//IL_0458: Unknown result type (might be due to invalid IL or missing references)
//IL_046a: Unknown result type (might be due to invalid IL or missing references)
//IL_047a: Unknown result type (might be due to invalid IL or missing references)
//IL_0485: Unknown result type (might be due to invalid IL or missing references)
//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
//IL_057b: Unknown result type (might be due to invalid IL or missing references)
//IL_0586: Unknown result type (might be due to invalid IL or missing references)
foreach (EnemyAI importEnemy in importEnemyList)
{
if (debugLibrary)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "/FindClosestEnemy/ item " + DebugStringHead(importEnemy) + " inside importEnemyList. IsEnemyDead: " + importEnemy.isEnemyDead));
}
}
if (debugLibrary && (Object)(object)importClosestEnemy != (Object)null)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "/FindClosestEnemy/ " + DebugStringHead(importClosestEnemy) + " inside importClosestEnemy. IsEnemyDead: " + importClosestEnemy.isEnemyDead));
}
if (debugLibrary)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "/FindClosestEnemy/ " + DebugStringHead(__instance) + " inside instance."));
}
if (importEnemyList.Count < 1)
{
if (debugLibrary)
{
LibraryLogger.LogWarning((object)(DebugStringHead(__instance) + "importEnemyList is empty!"));
}
if ((Object)(object)importClosestEnemy != (Object)null && importClosestEnemy.isEnemyDead)
{
if (!includeTheDead)
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogError((object)(DebugStringHead(__instance) + DebugStringHead(importClosestEnemy) + " is dead and importEnemyList is empty! Setting importClosestEnemy to null..."));
}
return null;
}
if (debugLibrary && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + DebugStringHead(importClosestEnemy) + " is dead and importEnemyList is empty!"));
}
return importClosestEnemy;
}
}
for (int i = 0; i < importEnemyList.Count; i++)
{
if ((Object)(object)importClosestEnemy == (Object)null)
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "No enemy assigned. Assigning new closestEnemy...."));
}
for (int j = i; j < importEnemyList.Count; j++)
{
if (importEnemyList[j].isEnemyDead && !includeTheDead)
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(__instance) + "Found dead enemy. Skipping...."));
}
continue;
}
if (debugLibrary && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "New closestEnemy found!"));
}
importClosestEnemy = importEnemyList[j];
break;
}
continue;
}
if (importClosestEnemy.isEnemyDead)
{
if (!includeTheDead)
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogError((object)(DebugStringHead(__instance) + ", " + DebugStringHead(__instance) + " is dead! Assigning new tempClosestEnemy from importEnemyList..."));
}
importClosestEnemy = importEnemyList[i];
continue;
}
if (debugLibrary && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + DebugStringHead(importClosestEnemy) + " is dead! The dead enemy will be included. "));
}
}
if ((Object)(object)importClosestEnemy == (Object)(object)importEnemyList[i])
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(__instance) + ((object)importEnemyList[i])?.ToString() + ", ID: " + ((Object)importEnemyList[i]).GetInstanceID() + " is already assigned as closestEnemy"));
}
}
else if ((Object)(object)importEnemyList[i] == (Object)null)
{
if (debugLibrary)
{
LibraryLogger.LogError((object)(DebugStringHead(__instance) + "Enemy not found! Skipping..."));
}
}
else if (Vector3.Distance(((Component)__instance).transform.position, ((Component)importEnemyList[i]).transform.position) < Vector3.Distance(((Component)__instance).transform.position, ((Component)importClosestEnemy).transform.position))
{
importClosestEnemy = importEnemyList[i];
if (debugLibrary && debugSpam)
{
LibraryLogger.LogDebug((object)(Vector3.Distance(((Component)__instance).transform.position, ((Component)importEnemyList[i]).transform.position) < Vector3.Distance(((Component)__instance).transform.position, ((Component)importClosestEnemy).transform.position)));
}
if (debugLibrary)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "Assigned " + ((object)importEnemyList[i])?.ToString() + ", ID: " + ((Object)importEnemyList[i]).GetInstanceID() + " as new closestEnemy. Distance: " + Vector3.Distance(((Component)__instance).transform.position, ((Component)importClosestEnemy).transform.position)));
}
}
}
if (debugLibrary && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(__instance) + "findClosestEnemy returning " + DebugStringHead(importClosestEnemy)));
}
return importClosestEnemy;
}
public static List<EnemyAI> FilterEnemyList(List<EnemyAI> importEnemyList, List<Type>? targetTypes, List<string>? blacklist, EnemyAI instance, bool inverseToggle = false, bool filterOutImmortal = true)
{
List<EnemyAI> list = new List<EnemyAI>();
for (int i = 0; i < importEnemyList.Count; i++)
{
if ((Object)(object)importEnemyList[i] == (Object)(object)instance)
{
if (debugLibrary)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "Found itself in importEnemyList! Skipping..."));
}
continue;
}
try
{
if (blacklist != null && (Object)(object)importEnemyList[i] != (Object)null && (blacklist.Contains(importEnemyList[i].enemyType.enemyName.ToUpper()) || ((Object)(object)((Component)importEnemyList[i]).GetComponentInChildren<ScanNodeProperties>() != (Object)null && blacklist.Contains(((Component)importEnemyList[i]).GetComponentInChildren<ScanNodeProperties>().headerText.ToUpper()))))
{
if (debugLibrary && blacklist.Contains(importEnemyList[i].enemyType.enemyName.ToUpper()))
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "Found blacklisted enemy in importEnemyList by EnemyType name! Skipping..."));
}
if (debugLibrary && blacklist.Contains(((Component)importEnemyList[i]).GetComponentInChildren<ScanNodeProperties>().headerText.ToUpper()))
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "Found blacklisted enemy in importEnemyList by scan node headertext! Skipping..."));
}
continue;
}
}
catch (Exception ex)
{
LibraryLogger.LogError((object)(DebugStringHead(instance) + "Something went wrong."));
LibraryLogger.LogError((object)blacklist);
LibraryLogger.LogError((object)importEnemyList[i]);
LibraryLogger.LogError((object)importEnemyList[i].enemyType.enemyName.ToUpper());
LibraryLogger.LogError((object)((Component)importEnemyList[i]).GetComponentInChildren<ScanNodeProperties>().headerText.ToUpper());
LibraryLogger.LogError((object)ex.ToString());
}
if (filterOutImmortal && !importEnemyList[i].enemyType.canDie)
{
if (debugLibrary)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "Caught and filtered out immortal Enemy of type " + ((object)importEnemyList[i]).GetType()));
}
continue;
}
if (targetTypes != null && targetTypes.Count > 0 && ((!inverseToggle && targetTypes.Contains(((object)importEnemyList[i]).GetType())) || (inverseToggle && !targetTypes.Contains(((object)importEnemyList[i]).GetType()))))
{
if (debugLibrary)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + "Enemy of type " + ((object)importEnemyList[i]).GetType()?.ToString() + " passed the filter. inverseToggle: " + inverseToggle));
}
list.Add(importEnemyList[i]);
}
else if (targetTypes != null && targetTypes.Count > 0)
{
if (debugLibrary)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "Caught and filtered out Enemy of type " + ((object)importEnemyList[i]).GetType()));
}
continue;
}
if (targetTypes == null || targetTypes.Count < 1)
{
if (debugLibrary && targetTypes != null && targetTypes.Count < 1)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "TargetTypes is empty. Adding enemy of type " + ((object)importEnemyList[i]).GetType()?.ToString() + " by default"));
}
if (debugLibrary && targetTypes == null)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "TargetTypes is NULL. Adding enemy of type " + ((object)importEnemyList[i]).GetType()?.ToString() + " by default"));
}
list.Add(importEnemyList[i]);
}
}
return list;
}
public static Dictionary<EnemyAI, float> GetEnemiesInLOS(EnemyAI instance, List<EnemyAI> importEnemyList, float width = 45f, float importRange = 0f, float proximityAwareness = -1f)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Invalid comparison between Unknown and I4
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: 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_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
List<EnemyAI> list = new List<EnemyAI>(importEnemyList);
Dictionary<EnemyAI, float> tempDictionary = new Dictionary<EnemyAI, float>();
float num = importRange;
if (instance.isOutside && !instance.enemyType.canSeeThroughFog && (int)TimeOfDay.Instance.currentLevelWeather == 3)
{
num = Mathf.Clamp(importRange, 0f, 30f);
}
if (list != null && list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
if ((Object)(object)list[i] == (Object)null)
{
if (debugLibrary)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: Enemy not found! Removing from tempList"));
}
list.Remove(list[i]);
continue;
}
Vector3 position = ((Component)list[i]).transform.position;
if (!(Vector3.Distance(position, instance.eye.position) < num) || Physics.Linecast(instance.eye.position, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) || !instance.CheckLineOfSightForPosition(position, width, (int)num, proximityAwareness, instance.eye))
{
continue;
}
if (!tempDictionary.ContainsKey(list[i]))
{
tempDictionary.Add(list[i], Vector3.Distance(((Component)instance).transform.position, position));
if (debugLibrary && debugSpam)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: Added " + ((object)list[i])?.ToString() + " to tempDictionary"));
}
}
if (tempDictionary.ContainsKey(list[i]) && debugLibrary && debugSpam && debugLibrary)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/:" + ((object)list[i])?.ToString() + " is already in tempDictionary"));
}
}
}
if (tempDictionary.Count > 1)
{
tempDictionary.OrderBy<KeyValuePair<EnemyAI, float>, Dictionary<EnemyAI, float>.ValueCollection>((KeyValuePair<EnemyAI, float> value) => tempDictionary.Values).Reverse();
if (debugLibrary)
{
foreach (KeyValuePair<EnemyAI, float> item in tempDictionary)
{
if (debugLibrary && debugSpam)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: Final list: " + ((object)item.Key)?.ToString() + ", range: " + item.Value));
}
}
}
}
return tempDictionary;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "fandovec03.NaturalSelectionLib";
public const string PLUGIN_NAME = "NaturalSelectionLib";
public const string PLUGIN_VERSION = "0.6.5";
}
}