using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using AIGraph;
using Agents;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Player;
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("SpawnAnalysis")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SpawnAnalysis")]
[assembly: AssemblyTitle("SpawnAnalysis")]
[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 SpawnAnalysis
{
internal static class Logger
{
private static ManualLogSource m_LogSource;
public static void SetupFromInit(ManualLogSource logSource)
{
m_LogSource = logSource;
}
private static string Format(object data)
{
return data.ToString();
}
public static void Debug(object msg)
{
m_LogSource.LogDebug((object)Format(msg));
}
public static void Info(object msg)
{
m_LogSource.LogInfo((object)Format(msg));
}
public static void Warn(object msg)
{
m_LogSource.LogWarning((object)Format(msg));
}
public static void Error(object msg)
{
m_LogSource.LogError((object)Format(msg));
}
public static void Fatal(object msg)
{
m_LogSource.LogFatal((object)Format(msg));
}
}
[BepInPlugin("tru0067.SpawnAnalysis", "SpawnAnalysis", "1.0.0")]
public class Plugin : BasePlugin
{
internal const string AUTHOR = "tru0067";
internal const string MODNAME = "SpawnAnalysis";
internal const string GUID = "tru0067.SpawnAnalysis";
internal const string VERSION = "1.0.0";
public override void Load()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
Logger.SetupFromInit(((BasePlugin)this).Log);
Logger.Info("SpawnAnalysis is loading...");
new Harmony("tru0067.SpawnAnalysis").PatchAll();
Logger.Info("SpawnAnalysis loaded!");
}
}
[HarmonyPatch]
internal static class SpawnAnalysis
{
internal const int NUM = 100;
internal static bool run = true;
[HarmonyPatch(typeof(SurvivalWave), "SpawnGroup")]
[HarmonyPrefix]
public static void SpawnGroupPatch()
{
run = true;
Logger.Info("==================== Spawn Info ====================");
}
[HarmonyPatch(typeof(SurvivalWave), "GetScoredSpawnPoint_DirectionalWeight")]
[HarmonyPostfix]
public static void GetScoredSpawnPoint_DirectionalWeightPatch(SurvivalWave __instance, ScoredSpawnPoint __result, Vector3 dir, float minDistance, float maxDistance)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
if (run)
{
SpawnParamsInfo(__instance, dir, minDistance, maxDistance);
AvailableSpawnsInfo(__instance, dir, minDistance, maxDistance);
WinningSpawnPointInfo(__result);
}
}
[HarmonyPatch(typeof(SurvivalWave), "GetScoredSpawnPoint")]
[HarmonyPostfix]
public static void GetScoredSpawnPointPatch(SurvivalWave __instance)
{
if (run)
{
run = false;
SpawnProbInfo(__instance);
}
}
public static void SpawnParamsInfo(SurvivalWave instance, Vector3 dir, float minDistance, float maxDistance)
{
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_013a: Unknown result type (might be due to invalid IL or missing references)
PlayerAgent val = default(PlayerAgent);
AIG_CourseNode val2 = ((!PlayerManager.TryGetClosestAlivePlayerAgent(instance.m_courseNode, ref val)) ? instance.m_courseNode : ((((Agent)val).CourseNode == null || !((Agent)val).CourseNode.IsValid) ? instance.m_courseNode : ((Agent)val).CourseNode));
Vector3 position = val2.Position;
Logger.Info($"Spawn parameters:\n minDistance: {minDistance:F1} maxDistance: {maxDistance:F1} dir: ({dir.x:F2} {dir.z:F2})\n alarmArea: {NodeName(instance.m_courseNode)} centerArea: {NodeName(val2)} centerAreaPos: ({position.x:F1} {position.z:F1})");
}
public static void AvailableSpawnsInfo(SurvivalWave instance, Vector3 dir, float minDistance, float maxDistance)
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_009f: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: 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_016e: Unknown result type (might be due to invalid IL or missing references)
Dictionary<int, (int, float, float)> dictionary = new Dictionary<int, (int, float, float)>();
int num = 0;
PlayerAgent val = default(PlayerAgent);
AIG_CourseNode val2 = ((!PlayerManager.TryGetClosestAlivePlayerAgent(instance.m_courseNode, ref val)) ? instance.m_courseNode : ((((Agent)val).CourseNode == null || !((Agent)val).CourseNode.IsValid) ? instance.m_courseNode : ((Agent)val).CourseNode));
List<ScoredSpawnPoint> availableSpawnPoints = instance.GetAvailableSpawnPoints(val2, 20);
Vector3 position = val2.Position;
Enumerator<ScoredSpawnPoint> enumerator = availableSpawnPoints.GetEnumerator();
while (enumerator.MoveNext())
{
ScoredSpawnPoint current = enumerator.Current;
Vector3 val3 = current.firstCoursePortal.Position - position;
val3.y = 0f;
Vector3 val4 = val3;
((Vector3)(ref val4)).Normalize();
current.m_dir = val4;
current.totalCost = Mathf.Clamp01(Vector3.Dot(val4, dir));
if ((double)current.pathHeat > (double)minDistance - 0.009999999776482582)
{
current.totalCost += (float)(1.0 + (1.0 - (double)Mathf.Clamp(current.pathHeat - minDistance, 0f, maxDistance) / (double)maxDistance));
}
dictionary[current.courseNode.NodeID] = (num, ((double)current.pathHeat > (double)minDistance - 0.009999999776482582) ? ((float)(1.0 + (1.0 - (double)Mathf.Clamp(current.pathHeat - minDistance, 0f, maxDistance) / (double)maxDistance))) : 0f, Mathf.Clamp01(Vector3.Dot(val4, dir)));
num++;
}
List<ScoredSpawnPoint> list = new List<ScoredSpawnPoint>();
Enumerator<ScoredSpawnPoint> enumerator2 = availableSpawnPoints.GetEnumerator();
while (enumerator2.MoveNext())
{
ScoredSpawnPoint current2 = enumerator2.Current;
list.Add(current2);
}
string text = "";
foreach (ScoredSpawnPoint item in list)
{
string text2 = $" index: {dictionary[item.courseNode.NodeID].Item1} pathCost: {dictionary[item.courseNode.NodeID].Item2} dirCost: {dictionary[item.courseNode.NodeID].Item3}";
text = text + SpawnPointInfo(item) + "\n" + text2 + "\n";
}
Logger.Info("Available Spawn Points:\n" + text.TrimEnd());
}
public static void WinningSpawnPointInfo(ScoredSpawnPoint winner)
{
Logger.Info("Winning spawn point:\n" + SpawnPointInfo(winner));
}
public static void SpawnProbInfo(SurvivalWave instance)
{
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_00de: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
Dictionary<int, int> dictionary = new Dictionary<int, int>();
Dictionary<int, string> dictionary2 = new Dictionary<int, string>();
for (int i = 0; i < 100; i++)
{
for (int j = 0; j < 100; j++)
{
float num = ((float)i + 0.5f) / 100f;
float num2 = ((float)j + 0.5f) / 100f;
Vector3 val = new Vector3(num, 0f, num2);
Vector3 normalized = ((Vector3)(ref val)).normalized;
ScoredSpawnPoint scoredSpawnPoint = instance.GetScoredSpawnPoint(normalized);
if (dictionary.ContainsKey(scoredSpawnPoint.courseNode.NodeID))
{
dictionary[scoredSpawnPoint.courseNode.NodeID]++;
}
else
{
dictionary[scoredSpawnPoint.courseNode.NodeID] = 1;
dictionary2[scoredSpawnPoint.courseNode.NodeID] = SpawnPointName(scoredSpawnPoint);
}
val = new Vector3(0f - num, 0f, 0f - num2);
normalized = ((Vector3)(ref val)).normalized;
scoredSpawnPoint = instance.GetScoredSpawnPoint(normalized);
if (dictionary.ContainsKey(scoredSpawnPoint.courseNode.NodeID))
{
dictionary[scoredSpawnPoint.courseNode.NodeID]++;
continue;
}
dictionary[scoredSpawnPoint.courseNode.NodeID] = 1;
dictionary2[scoredSpawnPoint.courseNode.NodeID] = SpawnPointName(scoredSpawnPoint);
}
}
string text = "";
foreach (KeyValuePair<int, int> item in dictionary.OrderBy((KeyValuePair<int, int> kv) => -kv.Value))
{
text += $"{dictionary2[item.Key]}: {100f * (float)item.Value / 20000f:F2}%\n";
}
Logger.Info("Spawn Probabilities:\n" + text.TrimEnd());
}
public static string SpawnPointInfo(ScoredSpawnPoint spawnPoint)
{
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_0109: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
return SpawnPointName(spawnPoint) + $"\n totalCost: {spawnPoint.totalCost} pathHeat: {spawnPoint.pathHeat} pathDistance: {spawnPoint.pathDistance}\n" + $" firstCoursePortal: {NodeName(spawnPoint.firstCoursePortal.m_nodeA)}-{NodeName(spawnPoint.firstCoursePortal.m_nodeB)} pos: ({spawnPoint.firstCoursePortal.Position.x:F1} {spawnPoint.firstCoursePortal.Position.z:F1}) m_dir: ({spawnPoint.m_dir.x:F2} {spawnPoint.m_dir.z:F2})";
}
public static string SpawnPointName(ScoredSpawnPoint spawnPoint)
{
return NodeName(spawnPoint.courseNode);
}
public static string NodeName(AIG_CourseNode courseNode)
{
return courseNode.m_zone.m_navInfo.Number + courseNode.m_area.m_navInfo.Suffix;
}
}
}