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.4")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.4.0")]
namespace ALaCart;
internal class GladiatorCartComponent : MonoBehaviour, Hoverable, Interactable
{
public string Name = "GladiatorAttach";
public float UseDistance = 2f;
public Transform AttachPoint;
private const string ZdoKeyAttachedPlayer = "ALaCart_AttachedPlayer";
private ZNetView _netView;
private float _lastSitTime;
private Player _attachedPlayer;
public void Awake()
{
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
_netView = ((Component)this).gameObject.GetComponentInParent<ZNetView>();
if (_netView.GetZDO() == null)
{
((Behaviour)this).enabled = false;
return;
}
_netView.Register<ZDOID>("ALaCart_RPC_Attach", (Action<long, ZDOID>)RPC_Attach);
_netView.Register("ALaCart_RPC_Detach", (Action<long>)RPC_Detach);
if (_netView.IsOwner())
{
ZDO zDO = _netView.GetZDO();
ZDOID zDOID = zDO.GetZDOID("ALaCart_AttachedPlayer");
if (zDOID != ZDOID.None && !Object.op_Implicit((Object)(object)ZNetScene.instance.FindInstance(zDOID)))
{
zDO.Set("ALaCart_AttachedPlayer", ZDOID.None);
}
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_0053: Unknown result type (might be due to invalid IL or missing references)
if (Object.op_Implicit((Object)(object)_attachedPlayer))
{
if (!Object.op_Implicit((Object)(object)AttachPoint))
{
Detach();
}
else if (ZInput.GetButtonDown("Jump") || ((Character)_attachedPlayer).IsDead())
{
Detach();
}
else
{
((Component)_attachedPlayer).transform.position = AttachPoint.position;
}
}
}
private void OnDestroy()
{
Detach();
}
private void Attach(Player player)
{
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
_attachedPlayer = player;
if (Object.op_Implicit((Object)(object)_netView) && _netView.GetZDO() != null)
{
_netView.InvokeRPC("ALaCart_RPC_Attach", new object[1] { ((Character)player).GetZDOID() });
}
}
private void Detach()
{
_attachedPlayer = null;
if (Object.op_Implicit((Object)(object)_netView) && _netView.GetZDO() != null)
{
_netView.InvokeRPC("ALaCart_RPC_Detach", Array.Empty<object>());
}
}
private void RPC_Attach(long sender, ZDOID playerId)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
ZDO zDO = _netView.GetZDO();
if (zDO != null && _netView.IsOwner())
{
zDO.Set("ALaCart_AttachedPlayer", playerId);
}
}
private void RPC_Detach(long sender)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
ZDO zDO = _netView.GetZDO();
if (zDO != null && _netView.IsOwner())
{
zDO.Set("ALaCart_AttachedPlayer", ZDOID.None);
}
}
private bool IsInUse()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
ZDO zDO = _netView.GetZDO();
if (zDO == null)
{
return false;
}
return zDO.GetZDOID("ALaCart_AttachedPlayer") != ZDOID.None;
}
public bool Interact(Humanoid human, bool hold, bool alt)
{
if (hold)
{
return false;
}
Player val = (Player)(object)((human is Player) ? human : null);
if (!Object.op_Implicit((Object)(object)val))
{
return false;
}
if (!Object.op_Implicit((Object)(object)AttachPoint))
{
return false;
}
if (!InUseDistance((Humanoid)(object)val))
{
return false;
}
if (Time.time - _lastSitTime < 2f)
{
return false;
}
if (Object.op_Implicit((Object)(object)_attachedPlayer) && (Object)(object)val == (Object)(object)_attachedPlayer)
{
Detach();
_lastSitTime = Time.time;
return true;
}
if (IsInUse())
{
return false;
}
Attach(val);
_lastSitTime = Time.time;
return true;
}
public bool UseItem(Humanoid user, ItemData item)
{
return false;
}
public string GetHoverText()
{
if (Time.time - _lastSitTime < 2f)
{
return "";
}
Player localPlayer = Player.m_localPlayer;
if (!Object.op_Implicit((Object)(object)localPlayer))
{
return "";
}
if (!InUseDistance((Humanoid)(object)localPlayer))
{
return Localization.instance.Localize("<color=grey>$piece_toofar</color>");
}
if (!Object.op_Implicit((Object)(object)_attachedPlayer) && IsInUse())
{
return Localization.instance.Localize("<color=grey>In use</color>");
}
return Localization.instance.Localize(Name + "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_use");
}
public string GetHoverName()
{
return Name;
}
private bool InUseDistance(Humanoid human)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)human) || !Object.op_Implicit((Object)(object)AttachPoint))
{
return false;
}
return Vector3.Distance(((Component)human).transform.position, AttachPoint.position) < UseDistance;
}
}
[BepInPlugin("de.sirskunkalot.ALaCart", "ALaCart", "0.0.4")]
[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.4";
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_004d: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Expected O, but got Unknown
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
try
{
PieceConfig val = new PieceConfig();
val.Name = "GladiatorCart";
val.Description = "Mountable cart. Feel like a gladiator.";
val.PieceTable = PieceTables.Hammer;
val.Category = PieceCategories.Misc;
val.Requirements = (RequirementConfig[])(object)new RequirementConfig[1]
{
new RequirementConfig("Wood", 1, 0, true)
};
CustomPiece val2 = new CustomPiece("GladiatorCart", "Cart", val);
val2.Piece.m_craftingStation = null;
val2.Piece.m_canBeRemoved = true;
PieceManager.Instance.AddPiece(val2);
Transform transform = val2.PiecePrefab.transform;
Object.DestroyImmediate((Object)(object)((Component)transform.Find("load")).gameObject);
GameObject val3 = new GameObject("AttachPointPlayer");
val3.transform.SetParent(transform, false);
val3.transform.SetAsFirstSibling();
val3.transform.localPosition = 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)$"Caught exception while creating cart: {arg}");
}
finally
{
PrefabManager.OnVanillaPrefabsAvailable -= CloneCart;
}
}
}