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.1.0")]
[assembly: AssemblyInformationalVersion("0.6.1+2f94e97e82aaa3313ca77a1062c8cbf1e63e93bf")]
[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.1.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.1")]
public class NaturalSelectionLib : BaseUnityPlugin
{
public static bool debugUnspecified = 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>());
if (debugSpam && debugUnspecified)
{
LibraryLogger.LogInfo((object)("/updateListInsideDictionary/ created new list for " + instanceType));
}
}
else
{
globalEnemyLists[instanceType] = list;
if (debugSpam && debugUnspecified)
{
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 Unspecified = false)
{
LibraryLogger = importLogger;
debugSpam = spammyLogs;
debugUnspecified = Unspecified;
}
public static string DebugStringHead(EnemyAI? __instance)
{
if (!Object.op_Implicit((Object)(object)__instance))
{
return "Unknown instance: ";
}
return ((__instance != null) ? ((Object)__instance).name : null) + ", local ID: " + ((__instance != null) ? new int?(((Object)__instance).GetInstanceID()) : 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> spawnedEnemies = RoundManager.Instance.SpawnedEnemies;
for (int i = 0; i < spawnedEnemies.Count; i++)
{
if ((Object)(object)spawnedEnemies[i] == (Object)(object)instance)
{
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + " Found itself in the list. Removing..."));
}
spawnedEnemies.RemoveAt(i);
}
else if (((object)spawnedEnemies[i]).GetType() == ((object)instance).GetType() && filterThemselves)
{
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + " Found its type in the list. Removing..."));
}
spawnedEnemies.RemoveAt(i);
}
else
{
if (!spawnedEnemies[i].isEnemyDead)
{
continue;
}
switch (includeOrReturnTheDead)
{
case 0:
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + " Found dead enemy in the list. Removing..."));
}
spawnedEnemies.RemoveAt(i);
break;
case 1:
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + " Found dead enemy in the list. Proceeding..."));
}
break;
case 2:
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + " Found living enemy in the list. Removing.."));
}
spawnedEnemies.RemoveAt(i);
break;
}
}
}
return spawnedEnemies;
}
public static List<EnemyAI> GetOutsideEnemyList(List<EnemyAI> importEnemyList, EnemyAI instance)
{
List<EnemyAI> list = new List<EnemyAI>();
foreach (EnemyAI importEnemy in importEnemyList)
{
if (importEnemy.isOutside && (Object)(object)importEnemy != (Object)(object)instance)
{
list.Add(importEnemy);
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + " Added " + DebugStringHead(importEnemy) + "..."));
}
}
}
return list;
}
public static List<EnemyAI> GetInsideEnemyList(List<EnemyAI> importEnemyList, EnemyAI instance)
{
List<EnemyAI> list = new List<EnemyAI>();
foreach (EnemyAI importEnemy in importEnemyList)
{
if (!importEnemy.isOutside && (Object)(object)importEnemy != (Object)(object)instance)
{
list.Add(importEnemy);
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + " Added " + DebugStringHead(importEnemy) + "..."));
}
}
}
return list;
}
public static EnemyAI? FindClosestEnemy(List<EnemyAI> importEnemyList, EnemyAI? importClosestEnemy, EnemyAI __instance, bool includeTheDead = false)
{
//IL_0453: Unknown result type (might be due to invalid IL or missing references)
//IL_0465: Unknown result type (might be due to invalid IL or missing references)
//IL_0475: Unknown result type (might be due to invalid IL or missing references)
//IL_0480: Unknown result type (might be due to invalid IL or missing references)
//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
//IL_0575: Unknown result type (might be due to invalid IL or missing references)
//IL_0580: Unknown result type (might be due to invalid IL or missing references)
EnemyAI val = importClosestEnemy;
foreach (EnemyAI importEnemy in importEnemyList)
{
if (debugUnspecified)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "/FindClosestEnemy/ item " + DebugStringHead(importEnemy) + " inside importEnemyList. IsEnemyDead: " + importEnemy.isEnemyDead));
}
}
if (debugUnspecified && (Object)(object)importClosestEnemy != (Object)null)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "/FindClosestEnemy/ " + DebugStringHead(importClosestEnemy) + " inside importClosestEnemy. IsEnemyDead: " + importClosestEnemy.isEnemyDead));
}
if (debugUnspecified)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "/FindClosestEnemy/ " + DebugStringHead(__instance) + " inside instance."));
}
if (importEnemyList.Count < 1)
{
if (debugUnspecified)
{
LibraryLogger.LogWarning((object)(DebugStringHead(__instance) + "importEnemyList is empty!"));
}
if ((Object)(object)importClosestEnemy != (Object)null && importClosestEnemy.isEnemyDead)
{
if (!includeTheDead)
{
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogError((object)(DebugStringHead(__instance) + DebugStringHead(importClosestEnemy) + " is dead and importEnemyList is empty! Setting importClosestEnemy to null..."));
}
}
else if (debugUnspecified && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + DebugStringHead(importClosestEnemy) + " is dead and importEnemyList is empty! The dead enemy will be included. "));
}
}
return null;
}
for (int i = 0; i < importEnemyList.Count; i++)
{
if ((Object)(object)val == (Object)null)
{
if (debugUnspecified && 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 (debugUnspecified && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(__instance) + "Found dead enemy. Skipping...."));
}
continue;
}
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + "New closestEnemy found!"));
}
val = importEnemyList[j];
break;
}
continue;
}
if (val.isEnemyDead)
{
if (!includeTheDead)
{
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogError((object)(DebugStringHead(__instance) + ", " + DebugStringHead(__instance) + " is dead! Assigning new tempClosestEnemy from importEnemyList..."));
}
val = importEnemyList[i];
continue;
}
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogInfo((object)(DebugStringHead(__instance) + DebugStringHead(importClosestEnemy) + " is dead! The dead enemy will be included. "));
}
}
if ((Object)(object)val == (Object)(object)importEnemyList[i])
{
if (debugUnspecified && 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 (debugUnspecified)
{
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)val).transform.position))
{
val = importEnemyList[i];
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogDebug((object)(Vector3.Distance(((Component)__instance).transform.position, ((Component)importEnemyList[i]).transform.position) < Vector3.Distance(((Component)__instance).transform.position, ((Component)val).transform.position)));
}
if (debugUnspecified)
{
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)val).transform.position)));
}
}
}
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogWarning((object)(DebugStringHead(__instance) + "findClosestEnemy returning " + DebugStringHead(val)));
}
return val;
}
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 (debugUnspecified)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "Found itself in importEnemyList! Skipping..."));
}
continue;
}
if (blacklist != null && blacklist.Count > 0 && (blacklist.Contains(importEnemyList[i].enemyType.enemyName.ToUpper()) || blacklist.Contains(((Component)importEnemyList[i]).GetComponentInChildren<ScanNodeProperties>().headerText.ToUpper())))
{
if (debugUnspecified && blacklist.Contains(importEnemyList[i].enemyType.enemyName.ToUpper()))
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "Found blacklisted enemy in importEnemyList by EnemyType name! Skipping..."));
}
if (debugUnspecified && 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;
}
if (targetTypes != null && targetTypes.Count > 0 && ((!inverseToggle && targetTypes.Contains(((object)importEnemyList[i]).GetType())) || (inverseToggle && !targetTypes.Contains(((object)importEnemyList[i]).GetType()))))
{
if (debugUnspecified)
{
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 && debugUnspecified && debugSpam && debugUnspecified)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "Caught and filtered out Enemy of type " + ((object)importEnemyList[i]).GetType()));
}
if (filterOutImmortal && !importEnemyList[i].enemyType.canDie)
{
if (debugUnspecified)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "Caught and filtered out immortal Enemy of type " + ((object)importEnemyList[i]).GetType()));
}
}
else if (targetTypes == null || targetTypes.Count < 1)
{
list.Add(importEnemyList[i]);
if (debugUnspecified && targetTypes != null && targetTypes.Count < 1)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "TargetTypes is empty. Added enemy of type " + ((object)importEnemyList[i]).GetType()?.ToString() + " to filteredList by default"));
}
if (debugUnspecified && targetTypes == null)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "TargetTypes is NULL. Added enemy of type " + ((object)importEnemyList[i]).GetType()?.ToString() + " to filteredList by default"));
}
}
}
return list;
}
public static Dictionary<EnemyAI, float> GetEnemiesInLOS(EnemyAI instance, List<EnemyAI> importEnemyList, float width = 45f, int importRange = 0, 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_019b: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
//IL_0232: Unknown result type (might be due to invalid IL or missing references)
//IL_0237: Unknown result type (might be due to invalid IL or missing references)
List<EnemyAI> list = new List<EnemyAI>();
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, 0, 30);
}
foreach (EnemyAI importEnemy in importEnemyList)
{
if (!((Object)(object)importEnemy != (Object)null))
{
continue;
}
if (debugUnspecified && debugSpam)
{
if (importEnemy.isEnemyDead)
{
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: " + ((object)importEnemy)?.ToString() + " is dead"));
}
LibraryLogger.LogInfo((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: Added " + ((object)importEnemy)?.ToString() + " to tempList"));
}
list.Add(importEnemy);
}
if (list != null && list.Count > 0)
{
for (int i = 0; i < list.Count; i++)
{
if ((Object)(object)list[i] == (Object)null)
{
if (debugUnspecified)
{
LibraryLogger.LogWarning((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: Enemy not found! Removing from tempList"));
}
list.RemoveAt(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 (debugUnspecified && debugSpam && debugUnspecified)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: Added " + ((object)list[i])?.ToString() + " to tempDictionary"));
}
}
if (tempDictionary.ContainsKey(list[i]) && debugUnspecified && debugSpam && debugUnspecified)
{
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);
if (debugUnspecified)
{
foreach (KeyValuePair<EnemyAI, float> item in tempDictionary)
{
if (debugUnspecified && debugSpam)
{
LibraryLogger.LogDebug((object)(DebugStringHead(instance) + "/GetEnemiesInLOS/: Final list: " + tempDictionary[item.Key]));
}
}
}
}
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.1";
}
}