Decompiled source of QuickCart v0.4.0

plugins/QuickCart.dll

Decompiled 6 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.4.0")]
[assembly: AssemblyInformationalVersion("0.4.0")]
[assembly: AssemblyVersion("0.4.0.0")]
public class AedenthornUtils
{
	public static bool IgnoreKeyPresses(bool extra = false)
	{
		if (!extra)
		{
			int result;
			if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible() && !ZNet.instance.InPasswordDialog())
			{
				Chat instance = Chat.instance;
				result = ((instance != null && instance.HasFocus()) ? 1 : 0);
			}
			else
			{
				result = 1;
			}
			return (byte)result != 0;
		}
		int result2;
		if (!((Object)(object)ZNetScene.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Minimap.IsOpen() && !Console.IsVisible() && !TextInput.IsVisible())
		{
			ZNet instance2 = ZNet.instance;
			if (instance2 == null || !instance2.InPasswordDialog())
			{
				Chat instance3 = Chat.instance;
				if ((instance3 == null || !instance3.HasFocus()) && !StoreGui.IsVisible() && !InventoryGui.IsVisible() && !Menu.IsVisible())
				{
					TextViewer instance4 = TextViewer.instance;
					result2 = ((instance4 != null && instance4.IsVisible()) ? 1 : 0);
					goto IL_00dc;
				}
			}
		}
		result2 = 1;
		goto IL_00dc;
		IL_00dc:
		return (byte)result2 != 0;
	}

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

[BepInPlugin("cjayride.QuickCart", "Quick Cart", "0.4.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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_004d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: 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 val4 = ((Component)val3).gameObject.GetComponent<Vagon>();
			if (!Object.op_Implicit((Object)(object)val4))
			{
				Transform parent = ((Component)val3).transform.parent;
				val4 = ((parent != null) ? ((Component)parent).gameObject.GetComponent<Vagon>() : null);
			}
			if (Object.op_Implicit((Object)(object)val3.attachedRigidbody) && Object.op_Implicit((Object)(object)val4) && Vector3.Distance(val3.ClosestPoint(val2), val2) < num && (val4.IsAttached((Character)(object)Player.m_localPlayer) || !val4.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);
		}
	}
}