Decompiled source of SwapItems v0.0.0

SwapItems.dll

Decompiled 5 days 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.Logging;
using CG.Client.Player.Interactions;
using CG.Client.Ship.Interactions;
using CG.Game.Player;
using CG.Objects;
using CG.Ship.Hull;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VoidManager;
using VoidManager.MPModChecks;

[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("SwapItems")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Template")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SwapItems")]
[assembly: AssemblyTitle("SwapItems")]
[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 SwapItems
{
	internal static class MyPluginInfo
	{
		internal const string PLUGIN_GUID = "id107.swapitems";

		internal const string PLUGIN_NAME = "SwapItems";

		internal const string PLUGIN_VERSION = "0.0.0";
	}
	[BepInPlugin("id107.swapitems", "SwapItems", "0.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(), "id107.swapitems");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin id107.swapitems is loaded!");
		}
	}
	[HarmonyPatch(typeof(CarryableInteract))]
	internal class CarryableInteractPatch
	{
		private static AbstractCarryableObject item1;

		private static AbstractCarryableObject item2;

		private static CarryablesSocket socket;

		private static LocalPlayer player;

		private static bool running;

		[HarmonyPrefix]
		[HarmonyPatch("StartCarryableInteraction", new Type[] { typeof(bool) })]
		private static bool StartCarryableInteraction(LocalPlayer ___player, bool ___isFetching, bool ___lockInteraction)
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Invalid comparison between Unknown and I4
			if (running)
			{
				return false;
			}
			player = ___player;
			if (___isFetching || ___lockInteraction || ((Player)player).IsBusy || (Object)(object)((Player)player).Payload == (Object)null)
			{
				return true;
			}
			AbstractInteractable current = player.RaycastHandler.Current;
			SocketInteractable val = (SocketInteractable)(object)((current is SocketInteractable) ? current : null);
			object obj;
			if (val == null)
			{
				obj = null;
			}
			else
			{
				CarryablesSocketActor socketActor = val.SocketActor;
				obj = ((socketActor != null) ? socketActor.Socket : null);
			}
			socket = (CarryablesSocket)obj;
			CarryablesSocket obj2 = socket;
			if ((Object)(object)((obj2 != null) ? obj2.Payload : null) == (Object)null || !socket.IsInput || !socket.IsOutput || (int)socket.CurrentState != 1 || !socket.DoesAccept(((Player)player).Payload))
			{
				return true;
			}
			running = true;
			item1 = ((Player)player).Payload;
			item2 = socket.Payload;
			socket.CarryableHandler.TryEjectCarryable(Vector3.up);
			Events.Instance.LateUpdate += PlaceItem;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch("PickupGrabable")]
		private static bool PickupGrabable(LocalPlayer ___player, bool ___isFetching, bool ___lockInteraction)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			if (running)
			{
				return false;
			}
			player = ___player;
			if (___lockInteraction || ___isFetching || (Object)(object)((Player)player).Payload == (Object)null)
			{
				return true;
			}
			AbstractInteractable current = ___player.RaycastHandler.Current;
			GrabableObject val = (GrabableObject)(object)((current is GrabableObject) ? current : null);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			running = true;
			item1 = ((Player)player).Payload;
			item2 = val.Carryable;
			((Player)player).CarryableHandler.TryEjectCarryable(Vector3.down);
			Events.Instance.LateUpdate += GrabItem;
			return false;
		}

		private static void PlaceItem(object sender, EventArgs e)
		{
			if ((Object)(object)socket.Payload == (Object)null)
			{
				Events.Instance.LateUpdate -= PlaceItem;
				socket.CarryableHandler.TryInsertCarryable(item1);
				Events.Instance.LateUpdate += GrabItem;
			}
		}

		private static void GrabItem(object sender, EventArgs e)
		{
			if ((Object)(object)((Player)player).Carrier.Payload == (Object)null)
			{
				Events.Instance.LateUpdate -= GrabItem;
				((Player)player).Carrier.TryInsertCarryable(item2).Then((Action)FixPosition);
				running = false;
			}
		}

		private static void FixPosition()
		{
			//IL_001c: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			GrabableObject component = ((Component)item2).GetComponent<GrabableObject>();
			Vector3 val = (component.UseOverrideHoldingAngle ? component.OverrideHoldingAngle : Vector3.zero);
			Transform subContainer = ((Player)player).Carrier.SubContainer;
			Vector3 position = subContainer.position + subContainer.right * component.CarryingOffset.x + subContainer.up * component.CarryingOffset.y + subContainer.forward * component.CarryingOffset.z;
			((Component)component).transform.position = position;
			((Component)component).transform.rotation = subContainer.rotation * Quaternion.Euler(val);
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public override MultiplayerType MPType => (MultiplayerType)3;

		public override string Author => "18107";

		public override string Description => "Allows the user to pick up and place items at the same time";
	}
}