Decompiled source of ALaCart v0.0.1

plugins\ALaCart.dll

Decompiled 11 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ALaCart")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ALaCart")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3f273733-869d-49eb-94f1-b83b1cc7e43b")]
[assembly: AssemblyFileVersion("0.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace ALaCart;

[BepInPlugin("de.sirskunkalot.ALaCart", "ALaCart", "0.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class ALaCart : BaseUnityPlugin
{
	public const string PluginGUID = "de.sirskunkalot.ALaCart";

	public const string PluginName = "ALaCart";

	public const string PluginVersion = "0.0.1";

	public const string AttachTransformName = "ALaCart_AttachPointPlayer";

	public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

	private void Awake()
	{
		PrefabManager.OnVanillaPrefabsAvailable += CloneCart;
	}

	private void CloneCart()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Expected O, but got Unknown
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Expected O, but got Unknown
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			PieceConfig val = new PieceConfig();
			val.Name = "GladiatorCart";
			val.PieceTable = "Hammer";
			val.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
			{
				new RequirementConfig("Wood", 1, 0, true)
			};
			CustomPiece val2 = new CustomPiece("GladiatorCart", "Cart", val);
			PieceManager.Instance.AddPiece(val2);
			Transform transform = val2.PiecePrefab.transform;
			Object.DestroyImmediate((Object)(object)((Component)transform.Find("load")).gameObject);
			((Component)transform).GetComponent<Rigidbody>().mass = 10f;
			GameObject val3 = new GameObject("ALaCart_AttachPointPlayer");
			val3.transform.SetParent(transform, false);
			val3.transform.SetAsFirstSibling();
			Transform transform2 = val3.transform;
			transform2.position += Vector3.up * 0.5f;
			GameObject gameObject = ((Component)transform.Find("Container")).gameObject;
			Object.DestroyImmediate((Object)(object)gameObject.GetComponent<Container>());
			gameObject.AddComponent<GladiatorCartComponent>().AttachPoint = val3.transform;
		}
		catch (Exception arg)
		{
			Logger.LogWarning((object)$"Catched exception while creating cart: {arg}");
		}
		finally
		{
			PrefabManager.OnVanillaPrefabsAvailable -= CloneCart;
		}
	}
}
internal class GladiatorCartComponent : MonoBehaviour, Hoverable, Interactable
{
	public string Name = "GladiatorAttach";

	public ZNetView NetView;

	public float UseDistance = 2f;

	private static float LastSitTime;

	public Transform AttachPoint;

	private Player AttachedPlayer;

	public void Awake()
	{
		NetView = ((Component)this).gameObject.GetComponentInParent<ZNetView>();
		if (NetView.GetZDO() == null)
		{
			((Behaviour)this).enabled = false;
		}
		else if (NetView.IsOwner())
		{
			Vagon componentInParent = ((Component)this).GetComponentInParent<Vagon>();
			float mass = 10f / (float)componentInParent.m_bodies.Length;
			Rigidbody[] bodies = componentInParent.m_bodies;
			for (int i = 0; i < bodies.Length; i++)
			{
				bodies[i].mass = mass;
			}
		}
	}

	public void Update()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)AttachedPlayer))
		{
			if (ZInput.GetButtonDown("Jump"))
			{
				AttachedPlayer = null;
			}
			else
			{
				((Component)AttachedPlayer).transform.position = AttachPoint.position;
			}
		}
	}

	public string GetHoverText()
	{
		if (Time.time - LastSitTime < 2f)
		{
			return "";
		}
		if (!InUseDistance((Humanoid)(object)Player.m_localPlayer))
		{
			return Localization.instance.Localize("<color=grey>$piece_toofar</color>");
		}
		return Localization.instance.Localize(Name + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use");
	}

	public string GetHoverName()
	{
		return Name;
	}

	public bool Interact(Humanoid human, bool hold, bool alt)
	{
		if (hold)
		{
			return false;
		}
		Player val = (Player)(object)((human is Player) ? human : null);
		if (!InUseDistance((Humanoid)(object)val))
		{
			return false;
		}
		if (Time.time - LastSitTime < 2f)
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)val))
		{
			if (((Character)val).IsEncumbered())
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)AttachedPlayer) && (Object)(object)val == (Object)(object)AttachedPlayer)
			{
				AttachedPlayer = null;
				return false;
			}
			AttachedPlayer = val;
			LastSitTime = Time.time;
		}
		return false;
	}

	public bool UseItem(Humanoid user, ItemData item)
	{
		return false;
	}

	private bool InUseDistance(Humanoid human)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		return Vector3.Distance(((Component)human).transform.position, AttachPoint.position) < UseDistance;
	}
}