Decompiled source of Random Spawns v1.1.0

RandomSpawns.dll

Decompiled 2 months 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RandomSpawns")]
[assembly: AssemblyTitle("RandomSpawns")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 Random_Spawn
{
	[BepInPlugin("Empress.Random_Spawn", "Random_Spawn", "1.1.0")]
	public class RandomSpawnPlugin : BaseUnityPlugin
	{
		internal Harmony Harmony;

		internal static RandomSpawnPlugin Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			Instance = this;
			Harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
			Harmony.PatchAll();
			Logger.LogInfo((object)"Random_Spawn loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "PlayerSpawn")]
	internal static class LevelGenerator_PlayerSpawn_Random_Spawn_Postfix
	{
		private static void Postfix(LevelGenerator __instance)
		{
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: 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_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: 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)
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			if (__instance.LevelPathPoints == null || __instance.LevelPathPoints.Count == 0)
			{
				RandomSpawnPlugin.Logger.LogWarning((object)"[Random_Spawn] No LevelPathPoints found, using vanilla spawn.");
				return;
			}
			List<LevelPoint> list = new List<LevelPoint>(__instance.LevelPathPoints);
			Shuffle(list);
			List<PlayerAvatar> playerList = GameDirector.instance.PlayerList;
			if (playerList == null || playerList.Count == 0)
			{
				RandomSpawnPlugin.Logger.LogWarning((object)"[Random_Spawn] No players found, leaving spawn unchanged.");
				return;
			}
			int num = 0;
			foreach (PlayerAvatar item in playerList)
			{
				if ((Object)(object)item == (Object)null)
				{
					continue;
				}
				LevelPoint val = list[num % list.Count];
				num++;
				Vector3 position = ((Component)val).transform.position;
				position.y += 0.1f;
				Quaternion val2 = Quaternion.identity;
				if ((Object)(object)__instance.LevelPathTruck != (Object)null)
				{
					Vector3 val3 = ((Component)__instance.LevelPathTruck).transform.position - position;
					val3.y = 0f;
					if (((Vector3)(ref val3)).sqrMagnitude > 0.01f)
					{
						val2 = Quaternion.LookRotation(((Vector3)(ref val3)).normalized, Vector3.up);
					}
				}
				item.Spawn(position, val2);
			}
		}

		private static void Shuffle<T>(IList<T> list)
		{
			for (int i = 0; i < list.Count; i++)
			{
				int num = Random.Range(i, list.Count);
				int index = i;
				int index2 = num;
				T value = list[num];
				T value2 = list[i];
				list[index] = value;
				list[index2] = value2;
			}
		}
	}
	[HarmonyPatch(typeof(PhysGrabber), "StartGrabbingPhysObject")]
	internal static class PhysGrabber_StartGrabbingPhysObject_Random_Spawn
	{
		private static Exception Finalizer(Exception __exception)
		{
			if (__exception is NullReferenceException)
			{
				RandomSpawnPlugin.Logger.LogWarning((object)"[Random_Spawn] Swallowed NullReference in PhysGrabber.StartGrabbingPhysObject.");
				return null;
			}
			return __exception;
		}
	}
}