Decompiled source of TeleportKeepItems v1.0.0

BepInEx/plugins/TeleportKeepItems/TeleportKeepItems.dll

Decompiled a day 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TeleportKeepItems")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2b0422e36730ee9c57eefad53b3fbdf49fb12744")]
[assembly: AssemblyProduct("TeleportKeepItems")]
[assembly: AssemblyTitle("TeleportKeepItems")]
[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 TeleportKeepItems
{
	[BepInPlugin("songzhearen.TeleportKeepItems", "TeleportKeepItems", "1.0.0")]
	public class TeleportKeepItemsPlugin : BaseUnityPlugin
	{
		internal static ConfigEntry<bool> KeepOnNormalTeleport;

		internal static ConfigEntry<bool> KeepOnInverseTeleport;

		internal static bool SkipNextDropItems;

		public static TeleportKeepItemsPlugin Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			KeepOnNormalTeleport = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "KeepOnNormalTeleport", true, new ConfigDescription("传送器传送时保留物品(普通传送器,从设施传送到飞船)", (AcceptableValueBase)null, Array.Empty<object>()));
			KeepOnInverseTeleport = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "KeepOnInverseTeleport", true, new ConfigDescription("传送器传送时保留物品(反向传送器,从飞船传送到设施)", (AcceptableValueBase)null, Array.Empty<object>()));
			try
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(KeepOnNormalTeleport, new BoolCheckBoxOptions()));
				LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(KeepOnInverseTeleport, new BoolCheckBoxOptions()));
			}
			catch (Exception ex)
			{
				Logger.LogDebug((object)("LethalConfig integration skipped: " + ex.Message));
			}
			Patch();
			Logger.LogInfo((object)"songzhearen.TeleportKeepItems v1.0.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("songzhearen.TeleportKeepItems");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "TeleportKeepItems";

		public const string PLUGIN_NAME = "TeleportKeepItems";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace TeleportKeepItems.Patches
{
	[HarmonyPatch(typeof(ShipTeleporter))]
	[HarmonyPatch("PressTeleportButtonClientRpc")]
	internal static class NormalTeleporter_SetFlag
	{
		[HarmonyPrefix]
		[HarmonyBefore(new string[] { "songzhearen.TeleportKeepItems" })]
		private static void Prefix(ShipTeleporter __instance)
		{
			try
			{
				if (TeleportKeepItemsPlugin.KeepOnNormalTeleport.Value && !__instance.isInverseTeleporter)
				{
					TeleportKeepItemsPlugin.SkipNextDropItems = true;
					TeleportKeepItemsPlugin.Logger.LogDebug((object)"Flag set for normal teleporter");
				}
			}
			catch (Exception ex)
			{
				TeleportKeepItemsPlugin.Logger.LogWarning((object)("NormalTeleporter_SetFlag error: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(ShipTeleporter))]
	[HarmonyPatch("TeleportPlayerOutWithInverseTeleporter")]
	internal static class InverseTeleporter_SetFlag
	{
		[HarmonyPrefix]
		[HarmonyBefore(new string[] { "songzhearen.TeleportKeepItems" })]
		private static void Prefix()
		{
			try
			{
				if (TeleportKeepItemsPlugin.KeepOnInverseTeleport.Value)
				{
					TeleportKeepItemsPlugin.SkipNextDropItems = true;
					TeleportKeepItemsPlugin.Logger.LogDebug((object)"Flag set for inverse teleporter");
				}
			}
			catch (Exception ex)
			{
				TeleportKeepItemsPlugin.Logger.LogWarning((object)("InverseTeleporter_SetFlag error: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	[HarmonyPatch("DropAllHeldItems")]
	internal static class SkipDropAllHeldItems
	{
		[HarmonyPrefix]
		[HarmonyBefore(new string[] { "songzhearen.TeleportKeepItems" })]
		private static bool Prefix(bool disconnecting)
		{
			try
			{
				if (!TeleportKeepItemsPlugin.SkipNextDropItems)
				{
					return true;
				}
				if (disconnecting)
				{
					return true;
				}
				TeleportKeepItemsPlugin.Logger.LogDebug((object)"Skipping DropAllHeldItems during teleport");
				return false;
			}
			catch (Exception ex)
			{
				TeleportKeepItemsPlugin.Logger.LogWarning((object)("SkipDropAllHeldItems error: " + ex.Message));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	[HarmonyPatch("DropAllHeldItemsAndSync")]
	internal static class SkipDropAllHeldItemsAndSync
	{
		[HarmonyPrefix]
		[HarmonyBefore(new string[] { "songzhearen.TeleportKeepItems" })]
		private static bool Prefix()
		{
			try
			{
				if (!TeleportKeepItemsPlugin.SkipNextDropItems)
				{
					return true;
				}
				TeleportKeepItemsPlugin.Logger.LogDebug((object)"Skipping DropAllHeldItemsAndSync during teleport");
				return false;
			}
			catch (Exception ex)
			{
				TeleportKeepItemsPlugin.Logger.LogWarning((object)("SkipDropAllHeldItemsAndSync error: " + ex.Message));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	[HarmonyPatch("TeleportPlayer")]
	internal static class ClearFlagAfterTeleport
	{
		[HarmonyPostfix]
		[HarmonyAfter(new string[] { "songzhearen.TeleportKeepItems" })]
		private static void Postfix()
		{
			try
			{
				if (TeleportKeepItemsPlugin.SkipNextDropItems)
				{
					TeleportKeepItemsPlugin.SkipNextDropItems = false;
					TeleportKeepItemsPlugin.Logger.LogDebug((object)"Flag cleared after TeleportPlayer");
				}
			}
			catch (Exception ex)
			{
				TeleportKeepItemsPlugin.Logger.LogWarning((object)("ClearFlagAfterTeleport error: " + ex.Message));
				TeleportKeepItemsPlugin.SkipNextDropItems = false;
			}
		}
	}
}