using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Pix.CartBuddy;
[BepInPlugin("Pix.CartBuddy", "CartBuddy", "0.9.1")]
public sealed class CartBuddyPlugin : BaseUnityPlugin
{
private sealed class RopeState
{
public LineRenderer Renderer;
public Transform RearPoint0;
public Transform RearPoint1;
public Transform CenterPoint;
public bool Initialized;
}
private sealed class RearPoints
{
public Transform RearPoint0;
public Transform RearPoint1;
public Transform CenterPoint;
}
public const string PluginGuid = "Pix.CartBuddy";
public const string PluginName = "CartBuddy";
public const string PluginVersion = "0.9.1";
private static CartBuddyPlugin _self;
private Harmony _harmony;
private static ConfigEntry<bool> _enabled;
private static ConfigEntry<string> _helperMode;
private static ConfigEntry<float> _helperHoldRange;
private static ConfigEntry<float> _holdCooldownSeconds;
private static ConfigEntry<float> _helperPointRadius;
private static ConfigEntry<int> _maxHelpers;
private static ConfigEntry<float> _helperLocalBack;
private static ConfigEntry<float> _helperLocalUp;
private static ConfigEntry<float> _helperLocalSide;
private static ConfigEntry<float> _assistAcceleration;
private static ConfigEntry<float> _assistMaxSpeedAdd;
private static ConfigEntry<float> _assistMinPullerSpeed;
private static ConfigEntry<float> _coastBrake;
private static ConfigEntry<float> _coastBrakeMaxSpeed;
private static ConfigEntry<float> _helperDamping;
private static ConfigEntry<float> _helperDampingMaxSpeed;
private static ConfigEntry<float> _weightReduction;
private static ConfigEntry<bool> _showHoverText;
private static ConfigEntry<bool> _showCenterMessages;
private static ConfigEntry<float> _tetherSlack;
private static ConfigEntry<float> _tetherPullMaxSpeed;
private static ConfigEntry<float> _tetherMaxStepPerFrame;
private static ConfigEntry<float> _tetherFollowVelocityFactor;
private static ConfigEntry<float> _tetherFollowVelocityMax;
private static ConfigEntry<float> _rearBackOffset;
private static ConfigEntry<float> _rearSideOffset;
private static ConfigEntry<float> _rearUpOffset;
private static ConfigEntry<float> _ropeSag;
private static ConfigEntry<float> _ropePlayerAnchorUp;
private static ConfigEntry<float> _ropeStartForwardNudge;
private static ConfigEntry<float> _ropeStartUpNudge;
private static ConfigEntry<float> _ropeStartSideNudge;
private static ConfigEntry<bool> _debugAllowHelpingWhileAttached;
private static ConfigEntry<bool> _debugShowRopeEvenIfNotPulled;
private static bool _localHelping;
private static WeakReference<Vagon> _localHelpingCart = new WeakReference<Vagon>(null);
private static float _lastHoldActionTime;
private static FieldInfo _fiAttachedObject;
private static FieldRef<Vagon, ConfigurableJoint> _frAttachJoin;
private static FieldInfo _fiBodies;
private static FieldInfo _fiBody;
private static FieldRef<Vagon, ZNetView> _frNview;
private static FieldInfo _fiItemWeightMassFactor;
private static readonly Dictionary<int, float> _origItemWeightFactor = new Dictionary<int, float>();
private static readonly Dictionary<int, RopeState> _rearRopes = new Dictionary<int, RopeState>();
private void Awake()
{
//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
//IL_04ce: Expected O, but got Unknown
_self = this;
_enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable CartBuddy.");
_helperMode = ((BaseUnityPlugin)this).Config.Bind<string>("Assist", "HelperMode", "FreeRun", "FreeRun, Attach, or Tether (experimental).");
_helperHoldRange = ((BaseUnityPlugin)this).Config.Bind<float>("Assist", "HelperHoldRange", 2.6f, "Hold-toggle range from cart center.");
_holdCooldownSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Assist", "HoldCooldownSeconds", 0.75f, "Cooldown between hold-toggle attempts.");
_helperPointRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Assist", "HelperPointRadius", 1.1f, "Helper counts within this radius of helper point.");
_maxHelpers = ((BaseUnityPlugin)this).Config.Bind<int>("Assist", "MaxHelpers", 1, "Maximum helpers at once.");
_helperLocalBack = ((BaseUnityPlugin)this).Config.Bind<float>("HelperAttachPoint", "LocalBack", -1.35f, "Helper point local Z (behind).");
_helperLocalUp = ((BaseUnityPlugin)this).Config.Bind<float>("HelperAttachPoint", "LocalUp", 0.15f, "Helper point local Y (up).");
_helperLocalSide = ((BaseUnityPlugin)this).Config.Bind<float>("HelperAttachPoint", "LocalSide", 0f, "Helper point local X (side).");
_assistAcceleration = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "AssistAcceleration", 15f, "Extra acceleration applied to cart when helpers active.");
_assistMaxSpeedAdd = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "AssistMaxSpeedAdd", 2.75f, "Stop adding assist if cart speed exceeds (puller speed + this).");
_assistMinPullerSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "AssistMinPullerSpeed", 0.85f, "Only apply assist when puller speed >= this.");
_coastBrake = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "CoastBrake", 7f, "Opposing acceleration applied when puller stops.");
_coastBrakeMaxSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "CoastBrakeMaxSpeed", 5f, "Only apply coast brake up to this cart speed.");
_helperDamping = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "HelperDamping", 2.75f, "Viscous damping applied to cart velocity while helpers active (adds resistance/tension).");
_helperDampingMaxSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "HelperDampingMaxSpeed", 10f, "Clamp for damping effect.");
_weightReduction = ((BaseUnityPlugin)this).Config.Bind<float>("Boosts", "WeightReduction", 0.2f, "Reduce load-based mass contribution by this fraction while helpers active.");
_showHoverText = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "ShowHoverText", true, "Show helper prompt on cart hover.");
_showCenterMessages = ((BaseUnityPlugin)this).Config.Bind<bool>("UI", "ShowCenterMessages", true, "Show a small center message when toggling helping.");
_tetherSlack = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "Slack", 1.6f, "Allowed drift before the tether starts pulling you back.");
_tetherPullMaxSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "PullMaxSpeed", 10f, "Max pull speed toward the tether point.");
_tetherMaxStepPerFrame = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "MaxStepPerFrame", 0.45f, "Max position correction per frame (stability).");
_tetherFollowVelocityFactor = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "FollowVelocityFactor", 0.65f, "How much cart motion drags you along when behind.");
_tetherFollowVelocityMax = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "FollowVelocityMax", 4.5f, "Clamp for cart drag-along velocity.");
_rearBackOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RearBackOffset", -0.55f, "Rear rope point extra Z offset (further back).");
_rearSideOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RearSideOffset", 0.35f, "Rear rope half-width (kept for future).");
_rearUpOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RearUpOffset", 0.75f, "Rear rope height.");
_ropeSag = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RopeSag", 0.22f, "How much the rope sags downward at the midpoint (visual).");
_ropePlayerAnchorUp = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RopePlayerAnchorUp", 1.05f, "Player rope anchor height above feet (visual).");
_ropeStartForwardNudge = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RopeStartForwardNudge", 0.85f, "Moves rope start toward cart body along cart forward axis. Positive = closer to cart.");
_ropeStartUpNudge = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RopeStartUpNudge", 0f, "Moves rope start up/down.");
_ropeStartSideNudge = ((BaseUnityPlugin)this).Config.Bind<float>("Tether", "RopeStartSideNudge", 0f, "Moves rope start left/right.");
_debugAllowHelpingWhileAttached = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "AllowHelpingWhileAttached", false, "Allow toggling helping while you are attached/pulling (solo testing).");
_debugShowRopeEvenIfNotPulled = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "ShowRopeEvenIfNotPulled", false, "Show rope even when cart is not being pulled (cosmetic preview).");
BindRefs();
_harmony = new Harmony("Pix.CartBuddy");
PatchVagonFixedUpdate();
PatchVagonLateUpdate();
PatchVagonInteract();
PatchVagonHoverText();
PatchVagonUpdateMass();
}
private void OnDestroy()
{
try
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
catch
{
}
}
private void Update()
{
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0143: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_014d: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0157: Unknown result type (might be due to invalid IL or missing references)
//IL_015c: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
//IL_0213: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
//IL_026a: Unknown result type (might be due to invalid IL or missing references)
//IL_026c: Unknown result type (might be due to invalid IL or missing references)
//IL_0271: Unknown result type (might be due to invalid IL or missing references)
//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
if (!_enabled.Value)
{
return;
}
Player localPlayer = Player.m_localPlayer;
if (!Object.op_Implicit((Object)(object)localPlayer))
{
return;
}
if (_localHelping)
{
if (_localHelpingCart.TryGetTarget(out var target) && Object.op_Implicit((Object)(object)target))
{
if (!IsWithinHelperPoint(target, ((Component)localPlayer).transform.position, _helperPointRadius.Value * 2.2f))
{
_localHelping = false;
_localHelpingCart.SetTarget(null);
}
}
else
{
_localHelping = false;
_localHelpingCart.SetTarget(null);
}
}
if (!IsTether() || !_localHelping || !_localHelpingCart.TryGetTarget(out var target2) || !Object.op_Implicit((Object)(object)target2) || (!_debugShowRopeEvenIfNotPulled.Value && !IsCartPulledNet(target2)))
{
return;
}
RearPoints orCreateRearPoints = GetOrCreateRearPoints(target2);
if (orCreateRearPoints == null || (Object)(object)orCreateRearPoints.CenterPoint == (Object)null)
{
return;
}
Vector3 ropeStartWorld = GetRopeStartWorld(target2, orCreateRearPoints.CenterPoint.position);
Vector3 val = ropeStartWorld - ((Component)localPlayer).transform.position;
val.y = 0f;
float magnitude = ((Vector3)(ref val)).magnitude;
float num = Mathf.Max(0.05f, _tetherSlack.Value);
if (magnitude <= num)
{
return;
}
Vector3 val2 = val / magnitude;
float deltaTime = Time.deltaTime;
if (deltaTime <= 0f)
{
return;
}
float num2 = Mathf.Max(0.1f, _tetherPullMaxSpeed.Value);
float val3 = Mathf.Max(0.02f, _tetherMaxStepPerFrame.Value);
float val4 = magnitude - num;
float num3 = Math.Min(val4, Math.Min(num2 * deltaTime, val3));
Vector3 val5 = val2 * num3;
Rigidbody val6 = GetBody(target2);
if ((Object)(object)val6 == (Object)null)
{
Rigidbody[] bodies = GetBodies(target2);
if (bodies != null && bodies.Length != 0)
{
val6 = bodies[0];
}
}
if ((Object)(object)val6 != (Object)null)
{
Vector3 val7 = val6.GetPointVelocity(ropeStartWorld);
val7.y = 0f;
float magnitude2 = ((Vector3)(ref val7)).magnitude;
float num4 = Mathf.Max(0.1f, _tetherFollowVelocityMax.Value);
if (magnitude2 > num4)
{
val7 *= num4 / magnitude2;
}
float num5 = Mathf.Clamp01(_tetherFollowVelocityFactor.Value);
val5 += val7 * (num5 * deltaTime);
}
Transform transform = ((Component)localPlayer).transform;
transform.position += val5;
}
private static bool IsFreeRun()
{
return string.Equals(_helperMode.Value, "FreeRun", StringComparison.OrdinalIgnoreCase);
}
private static bool IsAttach()
{
return string.Equals(_helperMode.Value, "Attach", StringComparison.OrdinalIgnoreCase);
}
private static bool IsTether()
{
return string.Equals(_helperMode.Value, "Tether", StringComparison.OrdinalIgnoreCase);
}
private void BindRefs()
{
Type typeFromHandle = typeof(Vagon);
BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
_fiAttachedObject = typeFromHandle.GetField("m_attachedObject", bindingAttr);
_frAttachJoin = AccessTools.FieldRefAccess<Vagon, ConfigurableJoint>("m_attachJoin");
_fiBodies = typeFromHandle.GetField("m_bodies", bindingAttr);
_fiBody = typeFromHandle.GetField("m_body", bindingAttr);
_frNview = AccessTools.FieldRefAccess<Vagon, ZNetView>("m_nview");
_fiItemWeightMassFactor = typeFromHandle.GetField("m_itemWeightMassFactor", bindingAttr);
}
private void PatchVagonFixedUpdate()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.Method(typeof(Vagon), "FixedUpdate", Type.EmptyTypes, (Type[])null);
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(CartBuddyPlugin), "Vagon_FixedUpdate_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private void PatchVagonLateUpdate()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.Method(typeof(Vagon), "LateUpdate", Type.EmptyTypes, (Type[])null);
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(CartBuddyPlugin), "Vagon_LateUpdate_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private void PatchVagonUpdateMass()
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0061: Expected O, but got Unknown
//IL_0061: Expected O, but got Unknown
MethodInfo methodInfo = AccessTools.Method(typeof(Vagon), "UpdateMass", Type.EmptyTypes, (Type[])null);
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(CartBuddyPlugin), "Vagon_UpdateMass_Prefix", (Type[])null), new HarmonyMethod(typeof(CartBuddyPlugin), "Vagon_UpdateMass_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private void PatchVagonHoverText()
{
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
MethodInfo methodInfo = typeof(Vagon).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name == "GetHoverText" && m.GetParameters().Length == 0 && m.ReturnType == typeof(string));
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(CartBuddyPlugin), "Vagon_GetHoverText_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private void PatchVagonInteract()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Expected O, but got Unknown
MethodInfo methodInfo = typeof(Vagon).GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault(delegate(MethodInfo m)
{
if (m.Name != "Interact")
{
return false;
}
ParameterInfo[] parameters = m.GetParameters();
return parameters.Length == 3 && typeof(Humanoid).IsAssignableFrom(parameters[0].ParameterType) && parameters[1].ParameterType == typeof(bool) && parameters[2].ParameterType == typeof(bool) && m.ReturnType == typeof(bool);
});
if (methodInfo != null)
{
_harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(CartBuddyPlugin), "Vagon_Interact_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
public static void Vagon_GetHoverText_Postfix(Vagon __instance, ref string __result)
{
try
{
if (!_enabled.Value || !_showHoverText.Value)
{
return;
}
Player localPlayer = Player.m_localPlayer;
if (Object.op_Implicit((Object)(object)localPlayer) && (_debugAllowHelpingWhileAttached.Value || !((Character)localPlayer).IsAttached()))
{
bool flag = IsLocalHelpingThisCart(__instance);
if (IsFreeRun() || IsTether())
{
__result += (flag ? "\n[Hold E] Stop helping (CartBuddy)" : "\n[Hold E] Help push (CartBuddy)");
}
else if (IsAttach())
{
__result += "\n[Hold E] Help push (CartBuddy)";
}
}
}
catch
{
}
}
public static bool Vagon_Interact_Prefix(Vagon __instance, Humanoid character, bool hold, bool alt, ref bool __result)
{
//IL_00c1: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
//IL_0152: Unknown result type (might be due to invalid IL or missing references)
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!_enabled.Value)
{
return true;
}
Player val = (Player)(object)((character is Player) ? character : null);
if (!Object.op_Implicit((Object)(object)val))
{
return true;
}
if (!_debugAllowHelpingWhileAttached.Value && ((Character)val).IsAttached())
{
return true;
}
if (!hold)
{
return true;
}
float time = Time.time;
if (time - _lastHoldActionTime < Mathf.Max(0.15f, _holdCooldownSeconds.Value))
{
__result = true;
return false;
}
float num = Mathf.Max(1.2f, _helperHoldRange.Value);
Vector3 val2 = ((Component)val).transform.position - ((Component)__instance).transform.position;
float magnitude = ((Vector3)(ref val2)).magnitude;
if (magnitude > num)
{
if (_showCenterMessages.Value)
{
((Character)val).Message((MessageType)2, "CartBuddy: get closer to the cart.", 0, (Sprite)null);
}
__result = true;
return false;
}
_lastHoldActionTime = time;
if (IsFreeRun() || IsTether())
{
float radius = Mathf.Max(0.35f, _helperPointRadius.Value);
bool flag = IsWithinHelperPoint(__instance, ((Component)val).transform.position, radius);
if (IsLocalHelpingThisCart(__instance))
{
_localHelping = false;
_localHelpingCart.SetTarget(null);
if (_showCenterMessages.Value)
{
((Character)val).Message((MessageType)2, "CartBuddy: stopped helping.", 0, (Sprite)null);
}
}
else
{
if (!flag)
{
if (_showCenterMessages.Value)
{
((Character)val).Message((MessageType)2, "CartBuddy: stand near the back to help push.", 0, (Sprite)null);
}
__result = true;
return false;
}
_localHelping = true;
_localHelpingCart.SetTarget(__instance);
if (_showCenterMessages.Value)
{
((Character)val).Message((MessageType)2, "CartBuddy: helping push.", 0, (Sprite)null);
}
}
}
else if (IsAttach())
{
Transform orCreateHelperAttachPoint = GetOrCreateHelperAttachPoint(__instance);
if (Object.op_Implicit((Object)(object)orCreateHelperAttachPoint))
{
((Character)val).AttachStart(orCreateHelperAttachPoint, ((Component)__instance).gameObject, true, false, false, "onGround", Vector3.zero, (Transform)null);
if (_showCenterMessages.Value)
{
((Character)val).Message((MessageType)2, "CartBuddy: helping push.", 0, (Sprite)null);
}
}
}
__result = true;
return false;
}
catch
{
return true;
}
}
private static bool IsLocalHelpingThisCart(Vagon cart)
{
if (!_localHelping)
{
return false;
}
Vagon target;
return _localHelpingCart.TryGetTarget(out target) && Object.op_Implicit((Object)(object)target) && (Object)(object)target == (Object)(object)cart;
}
private static bool IsCartPulledNet(Vagon v)
{
if ((Object)(object)v == (Object)null)
{
return false;
}
try
{
ZNetView val = ((_frNview != null) ? _frNview.Invoke(v) : null);
if ((Object)(object)val == (Object)null)
{
return false;
}
if (!val.IsValid())
{
return false;
}
ZDO zDO = val.GetZDO();
if (zDO == null)
{
return false;
}
return zDO.GetBool(ZDOVars.s_attachJointHash, false);
}
catch
{
return false;
}
}
private static Vector3 GetRopeStartWorld(Vagon cart, Vector3 baseWorld)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: 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_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0082: 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_0092: 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_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)cart == (Object)null)
{
return baseWorld;
}
float num = ((_ropeStartForwardNudge != null) ? _ropeStartForwardNudge.Value : 0f);
float num2 = ((_ropeStartUpNudge != null) ? _ropeStartUpNudge.Value : 0f);
float num3 = ((_ropeStartSideNudge != null) ? _ropeStartSideNudge.Value : 0f);
return baseWorld + ((Component)cart).transform.forward * num + ((Component)cart).transform.up * num2 + ((Component)cart).transform.right * num3;
}
public static void Vagon_UpdateMass_Prefix(Vagon __instance)
{
try
{
if (_enabled.Value && !(_fiItemWeightMassFactor == null) && IsHelpersActive(__instance))
{
int instanceID = ((Object)__instance).GetInstanceID();
if (!_origItemWeightFactor.ContainsKey(instanceID))
{
_origItemWeightFactor[instanceID] = (float)_fiItemWeightMassFactor.GetValue(__instance);
}
float num = _origItemWeightFactor[instanceID];
float num2 = Mathf.Clamp(_weightReduction.Value, 0f, 0.95f);
float num3 = Mathf.Clamp(1f - num2, 0.05f, 1f);
_fiItemWeightMassFactor.SetValue(__instance, num * num3);
}
}
catch
{
}
}
public static void Vagon_UpdateMass_Postfix(Vagon __instance)
{
try
{
if (!(_fiItemWeightMassFactor == null))
{
int instanceID = ((Object)__instance).GetInstanceID();
if (_origItemWeightFactor.TryGetValue(instanceID, out var value))
{
_fiItemWeightMassFactor.SetValue(__instance, value);
}
}
}
catch
{
}
}
public static void Vagon_LateUpdate_Postfix(Vagon __instance)
{
//IL_0101: Unknown result type (might be due to invalid IL or missing references)
//IL_0106: Unknown result type (might be due to invalid IL or missing references)
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0161: Unknown result type (might be due to invalid IL or missing references)
//IL_016b: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0181: Unknown result type (might be due to invalid IL or missing references)
//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!_enabled.Value)
{
return;
}
int instanceID = ((Object)__instance).GetInstanceID();
if (!_rearRopes.TryGetValue(instanceID, out var value) || value == null || !value.Initialized)
{
value = EnsureRearRope(__instance);
_rearRopes[instanceID] = value;
}
if (value == null || (Object)(object)value.Renderer == (Object)null || (Object)(object)value.CenterPoint == (Object)null)
{
return;
}
if (!IsTether() || !_localHelping || !IsLocalHelpingThisCart(__instance) || (!IsCartPulledNet(__instance) && !_debugShowRopeEvenIfNotPulled.Value))
{
((Renderer)value.Renderer).enabled = false;
return;
}
Player localPlayer = Player.m_localPlayer;
if (!Object.op_Implicit((Object)(object)localPlayer))
{
((Renderer)value.Renderer).enabled = false;
return;
}
Vector3 ropeStartWorld = GetRopeStartWorld(__instance, value.CenterPoint.position);
Vector3 val = ((Component)localPlayer).transform.position + Vector3.up * Mathf.Clamp(_ropePlayerAnchorUp.Value, 0.35f, 2f);
float num = Mathf.Clamp(_ropeSag.Value, 0f, 1.5f);
Vector3 val2 = (ropeStartWorld + val) * 0.5f + Vector3.down * num;
LineRenderer renderer = value.Renderer;
((Renderer)renderer).enabled = true;
renderer.positionCount = 3;
renderer.useWorldSpace = true;
renderer.SetPosition(0, ropeStartWorld);
renderer.SetPosition(1, val2);
renderer.SetPosition(2, val);
}
catch
{
}
}
public static void Vagon_FixedUpdate_Postfix(Vagon __instance)
{
//IL_0086: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_00ba: 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_013a: Unknown result type (might be due to invalid IL or missing references)
//IL_013f: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_0251: Unknown result type (might be due to invalid IL or missing references)
//IL_0255: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_0289: Unknown result type (might be due to invalid IL or missing references)
//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
try
{
if (!_enabled.Value || !IsHelpersActive(__instance))
{
return;
}
ApplyHelperDamping(__instance);
if (!IsCartPulledNet(__instance))
{
return;
}
ConfigurableJoint val = _frAttachJoin.Invoke(__instance);
if ((Object)(object)val == (Object)null || (Object)(object)((Joint)val).connectedBody == (Object)null)
{
return;
}
Rigidbody connectedBody = ((Joint)val).connectedBody;
Vector3 forward = ((Component)connectedBody).transform.forward;
forward.y = 0f;
if (((Vector3)(ref forward)).sqrMagnitude < 0.0001f)
{
return;
}
((Vector3)(ref forward)).Normalize();
Vector3 linearVelocity = connectedBody.linearVelocity;
float magnitude = ((Vector3)(ref linearVelocity)).magnitude;
Rigidbody[] array = GetBodies(__instance);
if (array == null || array.Length == 0)
{
Rigidbody body = GetBody(__instance);
if ((Object)(object)body != (Object)null)
{
array = (Rigidbody[])(object)new Rigidbody[1] { body };
}
}
if (array == null || array.Length == 0)
{
return;
}
Rigidbody val2 = array[0];
float num;
if (!((Object)(object)val2 != (Object)null))
{
num = 0f;
}
else
{
linearVelocity = val2.linearVelocity;
num = ((Vector3)(ref linearVelocity)).magnitude;
}
float num2 = num;
float num3 = Mathf.Max(0f, _assistMinPullerSpeed.Value);
if (magnitude >= num3)
{
float num4 = Mathf.Max(0f, _assistMaxSpeedAdd.Value);
if (!(num2 <= magnitude + num4))
{
return;
}
float num5 = Mathf.Max(0f, _assistAcceleration.Value);
Rigidbody[] array2 = array;
foreach (Rigidbody val3 in array2)
{
if (!((Object)(object)val3 == (Object)null))
{
val3.AddForce(forward * num5, (ForceMode)5);
}
}
return;
}
float num6 = Mathf.Max(0f, _coastBrake.Value);
float num7 = Mathf.Max(0.1f, _coastBrakeMaxSpeed.Value);
if (!(num2 > 0.05f) || !(num2 <= num7) || !((Object)(object)val2 != (Object)null))
{
return;
}
Vector3 linearVelocity2 = val2.linearVelocity;
Vector3 val4 = default(Vector3);
((Vector3)(ref val4))..ctor(linearVelocity2.x, 0f, linearVelocity2.z);
if (!(((Vector3)(ref val4)).sqrMagnitude > 0.0001f))
{
return;
}
Vector3 normalized = ((Vector3)(ref val4)).normalized;
Rigidbody[] array3 = array;
foreach (Rigidbody val5 in array3)
{
if (!((Object)(object)val5 == (Object)null))
{
val5.AddForce(-normalized * num6, (ForceMode)5);
}
}
}
catch
{
}
}
private static void ApplyHelperDamping(Vagon v)
{
//IL_00ba: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_0118: Unknown result type (might be due to invalid IL or missing references)
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: 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_012a: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Max(0f, _helperDamping.Value);
if (num <= 0f)
{
return;
}
Rigidbody[] array = GetBodies(v);
if (array == null || array.Length == 0)
{
Rigidbody body = GetBody(v);
if ((Object)(object)body != (Object)null)
{
array = (Rigidbody[])(object)new Rigidbody[1] { body };
}
}
if (array == null || array.Length == 0)
{
return;
}
float num2 = Mathf.Max(0.25f, _helperDampingMaxSpeed.Value);
Rigidbody[] array2 = array;
Vector3 val2 = default(Vector3);
foreach (Rigidbody val in array2)
{
if (!((Object)(object)val == (Object)null))
{
Vector3 linearVelocity = val.linearVelocity;
((Vector3)(ref val2))..ctor(linearVelocity.x, 0f, linearVelocity.z);
float magnitude = ((Vector3)(ref val2)).magnitude;
if (!(magnitude < 0.05f))
{
float num3 = Mathf.Min(magnitude, num2);
Vector3 val3 = ((magnitude > 0.0001f) ? (val2 / magnitude) : Vector3.zero);
Vector3 val4 = -val3 * (num * num3);
val.AddForce(val4, (ForceMode)5);
}
}
}
}
private static bool IsHelpersActive(Vagon v)
{
return CountHelpersAtPoint(v) > 0;
}
private static Rigidbody[] GetBodies(Vagon v)
{
if (_fiBodies == null)
{
return null;
}
try
{
return _fiBodies.GetValue(v) as Rigidbody[];
}
catch
{
return null;
}
}
private static Rigidbody GetBody(Vagon v)
{
if (_fiBody == null)
{
return null;
}
try
{
object? value = _fiBody.GetValue(v);
return (Rigidbody)((value is Rigidbody) ? value : null);
}
catch
{
return null;
}
}
private static Transform GetOrCreateHelperAttachPoint(Vagon vagon)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_0088: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)vagon))
{
return null;
}
Transform transform = ((Component)vagon).transform;
Transform val = transform.Find("CartBuddy_HelperAttachPoint");
if (Object.op_Implicit((Object)(object)val))
{
return val;
}
GameObject val2 = new GameObject("CartBuddy_HelperAttachPoint");
val2.transform.SetParent(transform, false);
val2.transform.localPosition = new Vector3(_helperLocalSide.Value, _helperLocalUp.Value, _helperLocalBack.Value);
val2.transform.localRotation = Quaternion.identity;
return val2.transform;
}
private static bool IsWithinHelperPoint(Vagon vagon, Vector3 pos, float radius)
{
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
Transform orCreateHelperAttachPoint = GetOrCreateHelperAttachPoint(vagon);
if (!Object.op_Implicit((Object)(object)orCreateHelperAttachPoint))
{
return false;
}
float num = Mathf.Max(0.25f, radius);
float num2 = num * num;
Vector3 val = pos - orCreateHelperAttachPoint.position;
return ((Vector3)(ref val)).sqrMagnitude <= num2;
}
private static int CountHelpersAtPoint(Vagon vagon)
{
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
Transform orCreateHelperAttachPoint = GetOrCreateHelperAttachPoint(vagon);
if (!Object.op_Implicit((Object)(object)orCreateHelperAttachPoint))
{
return 0;
}
float num = Mathf.Max(0.25f, _helperPointRadius.Value);
float num2 = num * num;
Player localPlayer = Player.m_localPlayer;
if ((Object)(object)localPlayer == (Object)null)
{
return 0;
}
GameObject val = null;
try
{
val = (GameObject)((_fiAttachedObject != null) ? /*isinst with value type is only supported in some contexts*/: null);
}
catch
{
}
if (!_localHelping)
{
return 0;
}
if (!_localHelpingCart.TryGetTarget(out var target) || !Object.op_Implicit((Object)(object)target) || (Object)(object)target != (Object)(object)vagon)
{
return 0;
}
if ((Object)(object)val != (Object)null && (Object)(object)((Component)localPlayer).gameObject == (Object)(object)val)
{
return 0;
}
Vector3 val2 = ((Component)localPlayer).transform.position - orCreateHelperAttachPoint.position;
if (((Vector3)(ref val2)).sqrMagnitude > num2)
{
return 0;
}
return 1;
}
private static RearPoints GetOrCreateRearPoints(Vagon vagon)
{
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Expected O, but got Unknown
//IL_005c: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_0136: Unknown result type (might be due to invalid IL or missing references)
//IL_0148: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: 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_00ce: Expected O, but got Unknown
//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
Transform transform = ((Component)vagon).transform;
Transform val = transform.Find("CartBuddy_RearRopePoint0");
Transform val2 = transform.Find("CartBuddy_RearRopePoint1");
Transform val3 = transform.Find("CartBuddy_RearRopePointC");
if ((Object)(object)val == (Object)null)
{
GameObject val4 = new GameObject("CartBuddy_RearRopePoint0");
val4.transform.SetParent(transform, false);
val4.transform.localRotation = Quaternion.identity;
val = val4.transform;
}
if ((Object)(object)val2 == (Object)null)
{
GameObject val5 = new GameObject("CartBuddy_RearRopePoint1");
val5.transform.SetParent(transform, false);
val5.transform.localRotation = Quaternion.identity;
val2 = val5.transform;
}
if ((Object)(object)val3 == (Object)null)
{
GameObject val6 = new GameObject("CartBuddy_RearRopePointC");
val6.transform.SetParent(transform, false);
val6.transform.localRotation = Quaternion.identity;
val3 = val6.transform;
}
float num = _helperLocalBack.Value + _rearBackOffset.Value;
float value = _rearUpOffset.Value;
float num2 = Mathf.Abs(_rearSideOffset.Value);
val3.localPosition = new Vector3(0f, value, num);
val.localPosition = new Vector3(num2, value, num);
val2.localPosition = new Vector3(0f - num2, value, num);
return new RearPoints
{
RearPoint0 = val,
RearPoint1 = val2,
CenterPoint = val3
};
}
private static RopeState EnsureRearRope(Vagon vagon)
{
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
RearPoints orCreateRearPoints = GetOrCreateRearPoints(vagon);
if (orCreateRearPoints == null || (Object)(object)orCreateRearPoints.CenterPoint == (Object)null)
{
return null;
}
int instanceID = ((Object)vagon).GetInstanceID();
if (_rearRopes.TryGetValue(instanceID, out var value) && value != null && (Object)(object)value.Renderer != (Object)null)
{
value.RearPoint0 = orCreateRearPoints.RearPoint0;
value.RearPoint1 = orCreateRearPoints.RearPoint1;
value.CenterPoint = orCreateRearPoints.CenterPoint;
value.Initialized = true;
return value;
}
GameObject val = new GameObject("CartBuddy_RearRopeRenderer");
val.transform.SetParent(((Component)vagon).transform, false);
LineRenderer val2 = val.AddComponent<LineRenderer>();
LineRenderer val3 = FindAnyLineRenderer(vagon);
if ((Object)(object)val3 != (Object)null)
{
CopyLineRenderer(val3, val2);
}
else
{
ApplyFallbackLineRendererStyle(val2);
}
val2.positionCount = 3;
((Renderer)val2).enabled = false;
val2.useWorldSpace = true;
return new RopeState
{
Renderer = val2,
RearPoint0 = orCreateRearPoints.RearPoint0,
RearPoint1 = orCreateRearPoints.RearPoint1,
CenterPoint = orCreateRearPoints.CenterPoint,
Initialized = true
};
}
private static LineRenderer FindAnyLineRenderer(Vagon vagon)
{
try
{
LineRenderer[] componentsInChildren = ((Component)vagon).GetComponentsInChildren<LineRenderer>(true);
if (componentsInChildren != null)
{
for (int i = 0; i < componentsInChildren.Length; i++)
{
if ((Object)(object)componentsInChildren[i] != (Object)null && (Object)(object)((Renderer)componentsInChildren[i]).sharedMaterial != (Object)null)
{
return componentsInChildren[i];
}
}
}
}
catch
{
}
return null;
}
private static void CopyLineRenderer(LineRenderer src, LineRenderer dst)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: 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_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)src == (Object)null) && !((Object)(object)dst == (Object)null))
{
((Renderer)dst).sharedMaterial = ((Renderer)src).sharedMaterial;
dst.widthMultiplier = src.widthMultiplier;
((Renderer)dst).shadowCastingMode = ((Renderer)src).shadowCastingMode;
((Renderer)dst).receiveShadows = ((Renderer)src).receiveShadows;
((Renderer)dst).lightProbeUsage = ((Renderer)src).lightProbeUsage;
((Renderer)dst).reflectionProbeUsage = ((Renderer)src).reflectionProbeUsage;
dst.textureMode = src.textureMode;
dst.alignment = src.alignment;
dst.numCornerVertices = src.numCornerVertices;
dst.numCapVertices = src.numCapVertices;
dst.useWorldSpace = true;
dst.startColor = src.startColor;
dst.endColor = src.endColor;
dst.startWidth = src.startWidth;
dst.endWidth = src.endWidth;
}
}
private static void ApplyFallbackLineRendererStyle(LineRenderer lr)
{
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
if (!((Object)(object)lr == (Object)null))
{
lr.useWorldSpace = true;
lr.alignment = (LineAlignment)0;
lr.textureMode = (LineTextureMode)0;
lr.numCornerVertices = 2;
lr.numCapVertices = 2;
Shader val = Shader.Find("Unlit/Texture");
if ((Object)(object)val == (Object)null)
{
val = Shader.Find("Legacy Shaders/Particles/Alpha Blended");
}
if ((Object)(object)val == (Object)null)
{
val = Shader.Find("Standard");
}
if ((Object)(object)val != (Object)null)
{
Material sharedMaterial = new Material(val);
((Renderer)lr).sharedMaterial = sharedMaterial;
}
lr.widthMultiplier = 0.07f;
lr.startWidth = 0.07f;
lr.endWidth = 0.07f;
lr.startColor = Color.white;
lr.endColor = Color.white;
}
}
}