Decompiled source of Mic Drop Drop Item Tweaks v1.0.1

MicDrop.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MicDrop")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MicDrop")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c15b15ba-bac9-4310-be81-e6fce034afb5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace MicDrop;

[BepInPlugin("goldenrevolver.MicDrop", "Mic Drop - Drop Item Tweaks", "1.0.1")]
public class MicDropPlugin : BaseUnityPlugin
{
	internal enum Toggle
	{
		Enabled,
		Disabled
	}

	internal enum DropHeight
	{
		Disabled,
		RightHand,
		Chest,
		Feet
	}

	internal enum DropForward
	{
		Disabled,
		ForChestAndFeet,
		Always
	}

	public const string NAME = "Mic Drop - Drop Item Tweaks";

	public const string VERSION = "1.0.1";

	internal static ConfigEntry<Toggle> StopMomentum;

	internal static ConfigEntry<DropHeight> DropPosition;

	internal static ConfigEntry<DropForward> DropInFront;

	internal static ConfigEntry<DropHeight> DropPositionWhileCrouching;

	internal static ConfigEntry<DropHeight> DropPositionWhileHoldingKeybind;

	internal static ConfigEntry<KeyboardShortcut> HeldKeybind;

	protected void Start()
	{
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		string text = "0 - General";
		StopMomentum = ((BaseUnityPlugin)this).Config.Bind<Toggle>(text, "StopMomentum", Toggle.Enabled, "Whether to throw or just drop the item.");
		DropPosition = ((BaseUnityPlugin)this).Config.Bind<DropHeight>(text, "DropPosition", DropHeight.Chest, "Drop position while not crouching and not holding the keybind.");
		DropInFront = ((BaseUnityPlugin)this).Config.Bind<DropForward>(text, "DropInFront", DropForward.Disabled, "Whether to drop the item one meter in front of the drop position like the base game.");
		text = "1 - Conditions";
		DropPositionWhileCrouching = ((BaseUnityPlugin)this).Config.Bind<DropHeight>(text, "DropPositionWhileCrouching", DropHeight.Feet, "Drop position while crouching.");
		DropPositionWhileHoldingKeybind = ((BaseUnityPlugin)this).Config.Bind<DropHeight>(text, "DropPositionWhileHoldingKeybind", DropHeight.Disabled, "Drop position while holding the keybind.");
		HeldKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>(text, "HeldKeybind", new KeyboardShortcut((KeyCode)0, Array.Empty<KeyCode>()), (ConfigDescription)null);
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
	}
}
[HarmonyPatch(typeof(ItemDrop))]
internal static class PatchThrow
{
	public static bool IsKeyHeld(this KeyboardShortcut shortcut)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		return (int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey) && ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
	}

	[HarmonyPatch("OnPlayerDrop")]
	[HarmonyPostfix]
	public static void OnPlayerDrop_Postfix(ItemDrop __instance)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_0174: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		Player closestPlayer = Player.GetClosestPlayer(((Component)__instance).transform.position, 5f);
		if (!Object.op_Implicit((Object)(object)closestPlayer) || (Object)(object)closestPlayer != (Object)(object)Player.m_localPlayer)
		{
			return;
		}
		MicDropPlugin.DropHeight value = MicDropPlugin.DropPosition.Value;
		if (MicDropPlugin.HeldKeybind.Value.IsKeyHeld())
		{
			value = MicDropPlugin.DropPositionWhileHoldingKeybind.Value;
		}
		else if (((Character)closestPlayer).IsCrouching())
		{
			value = MicDropPlugin.DropPositionWhileCrouching.Value;
		}
		switch (value)
		{
		case MicDropPlugin.DropHeight.Disabled:
			return;
		case MicDropPlugin.DropHeight.RightHand:
			if (Object.op_Implicit((Object)(object)((Humanoid)closestPlayer).m_visEquipment) && Object.op_Implicit((Object)(object)((Humanoid)closestPlayer).m_visEquipment.m_rightHand))
			{
				((Component)__instance).transform.position = ((Humanoid)closestPlayer).m_visEquipment.m_rightHand.position;
				break;
			}
			goto case MicDropPlugin.DropHeight.Chest;
		case MicDropPlugin.DropHeight.Chest:
			((Component)__instance).transform.position = ((Component)closestPlayer).transform.position + ((Component)closestPlayer).transform.up;
			break;
		case MicDropPlugin.DropHeight.Feet:
			((Component)__instance).transform.position = ((Component)closestPlayer).transform.position;
			break;
		}
		MicDropPlugin.DropForward value2 = MicDropPlugin.DropInFront.Value;
		MicDropPlugin.DropForward dropForward = value2;
		if (dropForward != MicDropPlugin.DropForward.ForChestAndFeet)
		{
			if (dropForward == MicDropPlugin.DropForward.Always)
			{
				goto IL_0162;
			}
		}
		else if (value != MicDropPlugin.DropHeight.RightHand)
		{
			goto IL_0162;
		}
		goto IL_0186;
		IL_0186:
		if (MicDropPlugin.StopMomentum.Value == MicDropPlugin.Toggle.Enabled)
		{
			Rigidbody component = ((Component)__instance).GetComponent<Rigidbody>();
			if (Object.op_Implicit((Object)(object)component))
			{
				((Component)__instance).transform.rotation = Quaternion.identity;
				component.velocity = Vector3.zero;
				((MonoBehaviour)__instance).StartCoroutine(StopThrow(component));
			}
		}
		return;
		IL_0162:
		Transform transform = ((Component)__instance).transform;
		transform.position += ((Component)closestPlayer).transform.forward;
		goto IL_0186;
	}

	private static IEnumerator StopThrow(Rigidbody body)
	{
		int lifeTimeFrames = 3;
		while (true)
		{
			int num = lifeTimeFrames - 1;
			lifeTimeFrames = num;
			if (num > 0)
			{
				if (Object.op_Implicit((Object)(object)body))
				{
					body.velocity = Vector3.zero;
				}
				yield return null;
				continue;
			}
			break;
		}
	}
}