Decompiled source of AlwaysInBounds v1.1.0

Tomatobird.AlwaysInBounds.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AlwaysInBounds.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
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("Tomatobird.AlwaysInBounds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2ea05ee7cf45a30b7eb26aac1c2213b8dcada25f")]
[assembly: AssemblyProduct("AlwaysInBounds")]
[assembly: AssemblyTitle("Tomatobird.AlwaysInBounds")]
[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 AlwaysInBounds
{
	[BepInPlugin("Tomatobird.AlwaysInBounds", "AlwaysInBounds", "1.0.0")]
	public class AlwaysInBounds : BaseUnityPlugin
	{
		public enum LocationType
		{
			Ship,
			Entrance,
			Dynamic
		}

		public static LocationType tpLocationType;

		public static bool spawnbody;

		public static AlwaysInBounds Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			string value = ((BaseUnityPlugin)this).Config.Bind<string>("General", "TpLocationConfig", "Dynamic", new ConfigDescription("Where to teleport player when player falls out of bounds", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Ship", "Entrance", "Dynamic" }), Array.Empty<object>())).Value;
			spawnbody = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "SpawnPlayerBody", true, "Player triggers always spawn player body").Value;
			tpLocationType = ((!(value == "Ship")) ? ((value == "Entrance") ? LocationType.Entrance : LocationType.Dynamic) : LocationType.Ship);
			Patch();
			Logger.LogInfo((object)"Tomatobird.AlwaysInBounds v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Tomatobird.AlwaysInBounds");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll(typeof(OutOfBoundsTriggerPatch));
			if (spawnbody)
			{
				Harmony.PatchAll(typeof(KillPlayerPatch));
			}
			Logger.LogDebug((object)"Finished patching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Tomatobird.AlwaysInBounds";

		public const string PLUGIN_NAME = "AlwaysInBounds";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace AlwaysInBounds.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class KillPlayerPatch
	{
		[HarmonyPatch("KillPlayer")]
		[HarmonyPrefix]
		private static bool KillPlayerMethodPatch(PlayerControllerB __instance, ref bool spawnBody)
		{
			spawnBody = true;
			return true;
		}
	}
	[HarmonyPatch(typeof(OutOfBoundsTrigger))]
	public class OutOfBoundsTriggerPatch
	{
		[HarmonyPatch("OnTriggerEnter")]
		[HarmonyPrefix]
		private static bool OnTriggerEnterPatch(OutOfBoundsTrigger __instance, ref Collider other)
		{
			//IL_00f7: 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_0167: 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)
			AlwaysInBounds.Logger.LogDebug((object)((Object)other).name.ToString());
			AlwaysInBounds.Logger.LogDebug((object)((Component)other).tag.ToString());
			if (((Component)other).tag != "Player" || (__instance.disableWhenRoundStarts && !__instance.playersManager.inShipPhase))
			{
				return true;
			}
			PlayerControllerB component = ((Component)other).GetComponent<PlayerControllerB>();
			if ((Object)(object)component == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)(object)component || !__instance.playersManager.shipDoorsEnabled)
			{
				return true;
			}
			if (!StartOfRound.Instance.isChallengeFile)
			{
				component.ResetFallGravity();
				switch (AlwaysInBounds.tpLocationType)
				{
				case AlwaysInBounds.LocationType.Ship:
					component.TeleportPlayer(__instance.playersManager.outsideShipSpawnPosition.position, false, 0f, false, true);
					break;
				case AlwaysInBounds.LocationType.Entrance:
					component.TeleportPlayer(Object.FindObjectOfType<EntranceTeleport>().entrancePoint.position, false, 0f, false, true);
					break;
				case AlwaysInBounds.LocationType.Dynamic:
					if (component.isInsideFactory)
					{
						component.TeleportPlayer(Object.FindObjectOfType<EntranceTeleport>().entrancePoint.position, false, 0f, false, true);
					}
					else
					{
						component.TeleportPlayer(__instance.playersManager.outsideShipSpawnPosition.position, false, 0f, false, true);
					}
					break;
				default:
					return true;
				}
				component.isInsideFactory = false;
				return false;
			}
			return true;
		}
	}
}