Decompiled source of QuickCart v0.7.0

QuickCart.dll

Decompiled a week ago
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace QuickCart;

[BepInPlugin("cjayride.QuickCart", "Quick Cart", "0.7.0")]
public class BepInExPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Vagon), "CanAttach")]
	private static class Vagon_CanAttach_Patch
	{
		private static bool Prefix(Vagon __instance, GameObject go, ref bool __result)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			if (!modEnabled.Value || !allowOutOfPlaceAttach.Value || ((Component)__instance).transform.up.y < 0.1f || (Object)(object)go != (Object)(object)((Component)Player.m_localPlayer).gameObject)
			{
				return true;
			}
			__result = !((Character)Player.m_localPlayer).IsTeleporting() && !((Character)Player.m_localPlayer).InDodge() && Vector3.Distance(go.transform.position + __instance.m_attachOffset, __instance.m_attachPoint.position) < attachDistance.Value;
			return false;
		}
	}

	private static readonly bool isDebug = true;

	public static ConfigEntry<string> hotKey;

	public static ConfigEntry<bool> modEnabled;

	public static ConfigEntry<float> attachDistance;

	public static ConfigEntry<bool> allowOutOfPlaceAttach;

	private static BepInExPlugin context;

	private void Awake()
	{
		context = this;
		hotKey = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Hotkey", "v", "The hotkey used to attach/detach a nearby cart");
		attachDistance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AttachDistance", 5f, "Maximum distance to attach a cart from.");
		allowOutOfPlaceAttach = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "AllowOutOfPlaceAttach", true, "Allow attaching the cart even when out of place");
		modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
		if (modEnabled.Value)
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}
	}

	private void Update()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		if (!modEnabled.Value || AedenthornUtils.IgnoreKeyPresses(extra: true) || !AedenthornUtils.CheckKeyDown(hotKey.Value))
		{
			return;
		}
		float num = attachDistance.Value;
		Vagon val = null;
		Vector3 val2 = ((Component)Player.m_localPlayer).transform.position + Vector3.up;
		Collider[] array = Physics.OverlapSphere(val2, attachDistance.Value);
		foreach (Collider val3 in array)
		{
			Vagon component = ((Component)val3).gameObject.GetComponent<Vagon>();
			if (!Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)((Component)val3).transform.parent))
			{
				component = ((Component)((Component)val3).transform.parent).gameObject.GetComponent<Vagon>();
			}
			if (Object.op_Implicit((Object)(object)val3.attachedRigidbody) && Object.op_Implicit((Object)(object)component) && Vector3.Distance(val3.ClosestPoint(val2), val2) < num && (component.IsAttached((Character)(object)Player.m_localPlayer) || !component.InUse()))
			{
				num = Vector3.Distance(val3.ClosestPoint(val2), val2);
				val = ((Component)((Component)val3).transform.parent).gameObject.GetComponent<Vagon>();
			}
		}
		if ((Object)(object)val != (Object)null)
		{
			val.Interact((Humanoid)(object)Player.m_localPlayer, false, false);
		}
	}
}
public class AedenthornUtils
{
	public static bool IgnoreKeyPresses(bool extra = false)
	{
		if ((Object)(object)ZNetScene.instance == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || Minimap.IsOpen() || Console.IsVisible() || TextInput.IsVisible())
		{
			return true;
		}
		if (!extra)
		{
			Chat instance = Chat.instance;
			if (!ZNet.instance.InPasswordDialog())
			{
				if ((Object)(object)instance != (Object)null)
				{
					return instance.HasFocus();
				}
				return false;
			}
			return true;
		}
		Chat instance2 = Chat.instance;
		TextViewer instance3 = TextViewer.instance;
		ZNet instance4 = ZNet.instance;
		if ((!((Object)(object)instance4 != (Object)null) || !instance4.InPasswordDialog()) && (!((Object)(object)instance2 != (Object)null) || !instance2.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible())
		{
			if ((Object)(object)instance3 != (Object)null)
			{
				return instance3.IsVisible();
			}
			return false;
		}
		return true;
	}

	public static bool CheckKeyDown(string value)
	{
		try
		{
			return Input.GetKeyDown(value.ToLower());
		}
		catch
		{
			return false;
		}
	}
}