Decompiled source of Faster Swap v1.0.0

FasterSwap.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CG.Client.Player.Interactions;
using CG.Client.Ship.Interactions;
using CG.Game.Player;
using CG.Objects;
using CG.Ship.Hull;
using CG.Space;
using Gameplay.Carryables;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using VoidManager;
using VoidManager.MPModChecks;
using VoidManager.ModMessages;
using VoidManager.Utilities;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("FasterSwap")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FasterSwap")]
[assembly: AssemblyTitle("Swaps items faster than vanilla")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace FasterSwap
{
	[HarmonyPatch(typeof(CarryableInteract), "StartInteraction")]
	internal class CarryableInteractPatch
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected O, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>
			{
				new CodeInstruction(OpCodes.Ldloc_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)null),
				new CodeInstruction(OpCodes.Callvirt, (object)null),
				new CodeInstruction(OpCodes.Callvirt, (object)null),
				new CodeInstruction(OpCodes.Ldarg_0, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)null),
				new CodeInstruction(OpCodes.Ldfld, (object)null),
				new CodeInstruction(OpCodes.Callvirt, (object)null),
				new CodeInstruction(OpCodes.Callvirt, (object)null)
			};
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			list2.Add(new CodeInstruction(OpCodes.Ldarg_1, (object)null));
			list2.Add(new CodeInstruction(OpCodes.Ldarg_0, (object)null));
			list2.Add(new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(CarryableInteractPatch), "HandleSwap", (Type[])null, (Type[])null)));
			List<CodeInstruction> list3 = list2;
			return HarmonyHelpers.PatchBySequence(instructions, (IEnumerable<CodeInstruction>)list, (IEnumerable<CodeInstruction>)list3, (PatchMode)1, (CheckMode)2, false);
		}

		public static bool HandleSwap(bool canSwap, AbstractInteractable interactable, CarryableInteract instance)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (!VoidManagerPlugin.Enabled)
			{
				return canSwap;
			}
			if (!canSwap)
			{
				return false;
			}
			CarryablesSocket socket = ((SocketInteractable)((interactable is SocketInteractable) ? interactable : null)).SocketActor.Socket;
			int viewID = ((MonoBehaviourPun)((Player)LocalPlayer.Instance).Payload).photonView.ViewID;
			MessageHandler.SendSwapRequest(((MonoBehaviourPun)socket).photonView.ViewID, viewID);
			CarryableObject payload = ((Player)LocalPlayer.Instance).Payload;
			((Player)LocalPlayer.Instance).Carrier.EjectCarryable(((Component)LocalPlayer.Instance).transform.rotation * Vector3.forward * 3f);
			((MonoBehaviourPun)payload).photonView.TransferOwnership(PhotonNetwork.MasterClient);
			GrabableObject component = ((Component)socket.Payload).GetComponent<GrabableObject>();
			((MonoBehaviour)LocalPlayer.Instance).StartCoroutine(instance.DelayedPickupGrabable((AbstractInteractable)(object)component));
			return false;
		}
	}
	internal class MessageHandler : ModMessage
	{
		private const int version = 1;

		public override void Handle(object[] arguments, Player sender)
		{
			if (!PhotonNetwork.IsMasterClient || arguments.Length < 1 || !(arguments[0] is int))
			{
				return;
			}
			int num = (int)arguments[0];
			CarryablesSocket socket;
			CarryableObject playerCarryable;
			if (1 != num)
			{
				BepinPlugin.Log.LogInfo((object)$"Got version {num} from {sender.NickName}, expected version {1}");
			}
			else if (arguments.Length == 3 && arguments[1] is int && arguments[2] is int)
			{
				int num2 = (int)arguments[1];
				int num3 = (int)arguments[2];
				socket = ((Component)PhotonView.Find(num2)).gameObject.GetComponent<CarryablesSocket>();
				playerCarryable = ((Component)PhotonView.Find(num3)).gameObject.GetComponent<CarryableObject>();
				if (((OrbitObject)playerCarryable).AmOwner)
				{
					checkSocketEmpty();
					return;
				}
				CarryableObject obj = playerCarryable;
				obj.OwnerChange = (Action<Player>)Delegate.Combine(obj.OwnerChange, new Action<Player>(waitForOwnerChange));
			}
			void checkSocketEmpty()
			{
				if ((Object)(object)socket.Payload == (Object)null)
				{
					playerItemToSocket();
				}
				else
				{
					socket.OnRemoveCarryable += waitForEmptySocket;
				}
			}
			void playerItemToSocket()
			{
				socket.TryInsertCarryable(playerCarryable);
			}
			void waitForEmptySocket(ICarrier _, CarryableObject __)
			{
				socket.OnRemoveCarryable -= waitForEmptySocket;
				playerItemToSocket();
			}
			void waitForOwnerChange(Player newOwner)
			{
				CarryableObject obj2 = playerCarryable;
				obj2.OwnerChange = (Action<Player>)Delegate.Remove(obj2.OwnerChange, new Action<Player>(waitForOwnerChange));
				checkSocketEmpty();
			}
		}

		public static void SendSwapRequest(int slotItemViewId, int playerItemViewId)
		{
			ModMessage.Send("id107.fasterswap", ModMessage.GetIdentifier(typeof(MessageHandler)), PhotonNetwork.MasterClient, new object[3] { 1, slotItemViewId, playerItemViewId }, false);
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "id107.fasterswap";

		public const string PLUGIN_NAME = "FasterSwap";

		public const string USERS_PLUGIN_NAME = "Faster Swap";

		public const string PLUGIN_VERSION = "1.0.0";

		public const string PLUGIN_DESCRIPTION = "Swaps items faster than vanilla";

		public const string PLUGIN_ORIGINAL_AUTHOR = "18107";

		public const string PLUGIN_AUTHORS = "18107";

		public const string PLUGIN_THUNDERSTORE_ID = "";
	}
	[BepInPlugin("id107.fasterswap", "Faster Swap", "1.0.0")]
	[BepInProcess("Void Crew.exe")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class BepinPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.fasterswap is loaded!");
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public static bool Enabled { get; private set; }

		public override MultiplayerType MPType => (MultiplayerType)14;

		public override string Author => "18107";

		public override string Description => "Swaps items faster than vanilla";

		public override string ThunderstoreID => "";

		public override SessionChangedReturn OnSessionChange(SessionChangedInput input)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Enabled = input.HostHasMod;
			return ((VoidPlugin)this).OnSessionChange(input);
		}
	}
}