Decompiled source of Throw To Slot v2.0.1

ThrowToSlot.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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;
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("ThrowToSlot")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("2.0.1.0")]
[assembly: AssemblyInformationalVersion("2.0.1+63afa73b5cb3cae92661f7325a426a54b20724d3")]
[assembly: AssemblyProduct("ThrowToSlot")]
[assembly: AssemblyTitle("If a thrown item hits an empty slot, it will be put in that slot.")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.0.1.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 ThrowToSlot
{
	[HarmonyPatch(typeof(CarryableInteract), "EndThrow")]
	internal class CarryableInteractPatch
	{
		private static readonly Dictionary<CarryableObject, (DateTime, CarryablesSocket, float)> thrown = new Dictionary<CarryableObject, (DateTime, CarryablesSocket, float)>();

		private static CarryablesSocket[] sockets = (CarryablesSocket[])(object)new CarryablesSocket[0];

		private static bool checksRunning = false;

		private static void Prefix(CarryableInteract __instance)
		{
			if (!VoidManagerPlugin.Enabled)
			{
				return;
			}
			object obj;
			if (__instance == null)
			{
				obj = null;
			}
			else
			{
				LocalPlayer player = __instance.player;
				obj = ((player != null) ? ((Player)player).Payload : null);
			}
			if (!((Object)obj == (Object)null))
			{
				CarryableObject payload = ((Player)__instance.player).Payload;
				if (thrown.ContainsKey(payload))
				{
					thrown.Remove(payload);
				}
				thrown.Add(payload, (DateTime.Now.AddMilliseconds(1500.0), null, float.PositiveInfinity));
				sockets = Object.FindObjectsOfType<CarryablesSocket>();
				if (!checksRunning)
				{
					checksRunning = true;
					Events.Instance.LateUpdate += CheckItems;
				}
			}
		}

		private static void CheckItems(object o, EventArgs e)
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			for (int num = thrown.Count - 1; num >= 0; num--)
			{
				KeyValuePair<CarryableObject, (DateTime, CarryablesSocket, float)> keyValuePair = thrown.ElementAt(num);
				var (dateTime, val, num2) = keyValuePair.Value;
				if (keyValuePair.Key.Carrier == null)
				{
					if (dateTime < DateTime.Now)
					{
						thrown.Remove(keyValuePair.Key);
						if ((double)num2 < 1.5 && val.isInput && (Object)(object)val.Payload == (Object)null)
						{
							val.TryInsertCarryable(keyValuePair.Key);
						}
					}
					else
					{
						CarryablesSocket[] array = sockets;
						foreach (CarryablesSocket val2 in array)
						{
							if (!((Object)(object)val2.Payload != (Object)null) && val2.isInput)
							{
								Vector3 val3 = ((Component)val2).transform.position - ((AbstractCloneStarObject)keyValuePair.Key).Transform.position;
								float magnitude = ((Vector3)(ref val3)).magnitude;
								if (magnitude < num2 && val2.DoesAccept(keyValuePair.Key) && (Object)(object)val2.Payload == (Object)null)
								{
									num2 = magnitude;
									val = val2;
								}
							}
						}
						if (!((Object)(object)val == (Object)null))
						{
							if (num2 < 0.75f)
							{
								val.TryInsertCarryable(keyValuePair.Key);
								thrown.Remove(keyValuePair.Key);
							}
							else
							{
								thrown[keyValuePair.Key] = (dateTime, val, num2);
							}
						}
					}
				}
			}
			if (thrown.Count == 0)
			{
				Events.Instance.LateUpdate -= CheckItems;
				checksRunning = false;
			}
		}
	}
	public class MyPluginInfo
	{
		public const string PLUGIN_GUID = "id107.throwtoslot";

		public const string PLUGIN_NAME = "ThrowToSlot";

		public const string USERS_PLUGIN_NAME = "Throw To Slot";

		public const string PLUGIN_VERSION = "2.0.1";

		public const string PLUGIN_DESCRIPTION = "If a thrown item hits an empty slot, it will be put in that slot.";

		public const string PLUGIN_ORIGINAL_AUTHOR = "18107";

		public const string PLUGIN_AUTHORS = "18107";

		public const string PLUGIN_THUNDERSTORE_ID = "NihilityShift/Throw_To_Slot";
	}
	[BepInPlugin("id107.throwtoslot", "Throw To Slot", "2.0.1")]
	[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.throwtoslot is loaded!");
		}
	}
	public class VoidManagerPlugin : VoidPlugin
	{
		public static bool Enabled { get; private set; }

		public override MultiplayerType MPType => (MultiplayerType)8;

		public override string Author => "18107";

		public override string Description => "If a thrown item hits an empty slot, it will be put in that slot.";

		public override string ThunderstoreID => "NihilityShift/Throw_To_Slot";

		public override SessionChangedReturn OnSessionChange(SessionChangedInput input)
		{
			//IL_0001: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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)
			Enabled = input.IsMod_Session;
			SessionChangedReturn result = default(SessionChangedReturn);
			result.SetMod_Session = true;
			return result;
		}
	}
}