Decompiled source of TooLittleSpawns v1.0.0

TooLittleSpawns.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG;
using HG.Reflection;
using Microsoft.CodeAnalysis;
using On.RoR2;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Navigation;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: OptIn]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TooLittleSpawns")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+42850489308cf6a0acc26e8d04056d65fcdee6fa")]
[assembly: AssemblyProduct("TooLittleSpawns")]
[assembly: AssemblyTitle("TooLittleSpawns")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 TooLittleSpawns
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			if (TooLittleSpawns.debug.Value)
			{
				_logSource.LogDebug(data);
			}
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	internal static class ROOSupport
	{
		internal static void SliderConfig(float min, float max, ConfigEntry<float> config)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			StepSliderConfig val = new StepSliderConfig
			{
				max = max,
				min = min,
				FormatString = "{0:0}"
			};
			ModSettingsManager.AddOption((BaseOption)new StepSliderOption(config, val));
		}

		internal static void SliderConfig(int min, int max, ConfigEntry<int> config)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			IntSliderConfig val = new IntSliderConfig
			{
				max = max,
				min = min,
				formatString = "{0:0}"
			};
			ModSettingsManager.AddOption((BaseOption)new IntSliderOption(config, val));
		}

		internal static void CheckboxConfig(ConfigEntry<bool> config, bool restartRequired = false)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			CheckBoxConfig val = new CheckBoxConfig();
			((BaseOptionConfig)val).restartRequired = restartRequired;
			ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(config, val));
		}

		internal static void StringConfig(ConfigEntry<string> config)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			InputFieldConfig val = new InputFieldConfig();
			ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(config, val));
		}

		internal static void KeyboardConfig(ConfigEntry<KeyboardShortcut> config)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			KeyBindConfig val = new KeyBindConfig();
			ModSettingsManager.AddOption((BaseOption)new KeyBindOption(config, val));
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("kina.TooLittleSpawns", "TooLittleSpawns", "1.0.0")]
	public class TooLittleSpawns : BaseUnityPlugin
	{
		private const string PluginGUID = "kina.TooLittleSpawns";

		private const string PluginAuthor = "kina";

		private const string PluginName = "TooLittleSpawns";

		private const string PluginVersion = "1.0.0";

		private static ConfigEntry<int> playerBehavior;

		public static ConfigEntry<bool> debug;

		private GameObject teleporterObject;

		private SpawnPoint initialSpawn;

		private List<SpawnPoint> newSpawns = new List<SpawnPoint>();

		private static bool UHRInstalled => Chainloader.PluginInfos.ContainsKey("iDeathHD.UnityHotReload");

		private static bool ROOInstalled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");

		public void Awake()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			Log.Init(((BaseUnityPlugin)this).Logger);
			playerBehavior = ((BaseUnityPlugin)this).Config.Bind<int>("TooLittleSpawns", "Max players needed to use new behavior", 4, "Max players limit to determine whether or not to use new behavior. Note that this is the limit, not the amount of players.");
			if (ROOInstalled)
			{
				ROOSupport.SliderConfig(1, 16, playerBehavior);
			}
			debug = ((BaseUnityPlugin)this).Config.Bind<bool>("TooLittleSpawns", "Log debug", false, "Whether to use debug logging or not. Logs whether a spawn is using a spawnpoint, creating it from the nodegraph and other stuff if you're paranoid about it working or something");
			if (ROOInstalled)
			{
				ROOSupport.CheckboxConfig(debug);
			}
			SceneDirector.PlaceTeleporter += new hook_PlaceTeleporter(SceneDirectorOnPlaceTeleporter);
			SpawnPoint.ConsumeSpawnPoint += new hook_ConsumeSpawnPoint(SpawnPointOnConsumeSpawnPoint);
		}

		private void SceneDirectorOnPlaceTeleporter(orig_PlaceTeleporter orig, SceneDirector self)
		{
			orig.Invoke(self);
			teleporterObject = self.teleporterInstance;
		}

		private SpawnPoint SpawnPointOnConsumeSpawnPoint(orig_ConsumeSpawnPoint orig)
		{
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0367: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: 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_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: 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_0261: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: 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_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			if (RoR2Application.maxPlayers <= 4)
			{
				return orig.Invoke();
			}
			if (!Object.op_Implicit((Object)(object)initialSpawn))
			{
				Log.Debug("creating initial spawn .,,.");
				List<SpawnPoint> list = new List<SpawnPoint>(SpawnPoint.readOnlyInstancesList);
				list.Sort(delegate(SpawnPoint a, SpawnPoint b)
				{
					//IL_000b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0010: Unknown result type (might be due to invalid IL or missing references)
					//IL_0026: Unknown result type (might be due to invalid IL or missing references)
					//IL_0031: Unknown result type (might be due to invalid IL or missing references)
					//IL_0036: Unknown result type (might be due to invalid IL or missing references)
					//IL_003b: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val12 = teleporterObject.transform.position;
					float sqrMagnitude = ((Vector3)(ref val12)).sqrMagnitude;
					val12 = teleporterObject.transform.position - ((Component)b).transform.position;
					return sqrMagnitude.CompareTo(((Vector3)(ref val12)).sqrMagnitude);
				});
				initialSpawn = list[list.Count - 1];
				initialSpawn.consumed = true;
				newSpawns.Add(initialSpawn);
				return initialSpawn;
			}
			SpawnPoint val = null;
			float num = float.MaxValue;
			foreach (SpawnPoint readOnlyInstances in SpawnPoint.readOnlyInstancesList)
			{
				if (!readOnlyInstances.consumed)
				{
					float num2 = Vector3.Distance(((Component)readOnlyInstances).gameObject.transform.position, ((Component)initialSpawn).gameObject.transform.position);
					if (num2 < num && num2 < 40f)
					{
						val = readOnlyInstances;
						num = num2;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				NodeGraph groundNodes = SceneInfo.instance.groundNodes;
				NodeFlags val2 = (NodeFlags)0;
				NodeFlags val3 = (NodeFlags)0;
				val3 = (NodeFlags)(val3 | 4);
				List<NodeIndex> list2 = groundNodes.GetActiveNodesForHullMaskWithFlagConditions((HullMask)2, val2, val3);
				Vector3 val4 = default(Vector3);
				for (int num3 = 0; num3 < list2.Count; num3++)
				{
					if (!SceneDirector.IsNodeSuitableForPod(groundNodes, list2[num3]))
					{
						groundNodes.GetNodePosition(list2[num3], ref val4);
						list2.RemoveAt(num3);
					}
				}
				if (PlayerSpawnInhibitor.readOnlyInstancesList.Count > 0)
				{
					List<NodeIndex> list3 = new List<NodeIndex>();
					for (int num4 = 0; num4 < list2.Count; num4++)
					{
						bool flag = false;
						foreach (PlayerSpawnInhibitor readOnlyInstances2 in PlayerSpawnInhibitor.readOnlyInstancesList)
						{
							if (readOnlyInstances2.IsInhibiting(groundNodes, list2[num4]))
							{
								flag = true;
								break;
							}
						}
						if (!flag)
						{
							list3.Add(list2[num4]);
						}
					}
					if (list3.Count > 0)
					{
						list2 = list3;
					}
				}
				num = float.MaxValue;
				NodeIndex? val5 = null;
				Vector3 val6 = default(Vector3);
				foreach (NodeIndex item in list2)
				{
					groundNodes.GetNodePosition(item, ref val6);
					bool flag2 = false;
					foreach (SpawnPoint newSpawn in newSpawns)
					{
						if (Object.op_Implicit((Object)(object)newSpawn) && ((Component)newSpawn).gameObject.transform.position == val6)
						{
							flag2 = true;
						}
						if (Object.op_Implicit((Object)(object)newSpawn) && Vector3.Distance(((Component)newSpawn).gameObject.transform.position, val6) < 5f)
						{
							flag2 = true;
						}
					}
					if (!flag2)
					{
						float num5 = Vector3.Distance(val6, ((Component)initialSpawn).gameObject.transform.position);
						if (num5 < num)
						{
							val5 = item;
							num = num5;
						}
					}
				}
				if (!val5.HasValue)
				{
					Log.Error("new spawn node is null ! gorp ,.., falling back on first spawn entry ,..,");
					return SpawnPoint.readOnlyInstancesList[0];
				}
				Vector3 val7 = default(Vector3);
				groundNodes.GetNodePosition(val5.Value, ref val7);
				List<LinkIndex> list4 = CollectionPool<LinkIndex, List<LinkIndex>>.RentCollection();
				groundNodes.GetActiveNodeLinks(val5.Value, list4);
				Quaternion val10;
				if (list4.Count > 0)
				{
					LinkIndex val8 = Run.instance.spawnRng.NextElementUniform<LinkIndex>(list4);
					Vector3 val9 = default(Vector3);
					groundNodes.GetNodePosition(groundNodes.GetLinkEndNode(val8), ref val9);
					val10 = Util.QuaternionSafeLookRotation(val9 - val7);
				}
				else
				{
					val10 = Quaternion.Euler(0f, Run.instance.spawnRng.nextNormalizedFloat * 360f, 0f);
				}
				GameObject val11 = Object.Instantiate<GameObject>(SpawnPoint.prefab, val7, val10);
				val = val11.GetComponent<SpawnPoint>();
				newSpawns.Add(val);
				Log.Debug($"finalized spawn from nodegraph {val11.transform.position} !");
			}
			else
			{
				Log.Debug($"got spawn from spawnlist {((Component)val).gameObject.transform.position}");
			}
			val.consumed = true;
			return val;
		}

		private void Update()
		{
		}
	}
}