using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using HarmonyLib; using Jotunn.Utils; using UnityEngine; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: CompilationRelaxations(8)] [assembly: AssemblyVersion("0.0.0.0")] [BepInPlugin("fix.vagon.cartweightfix", "CartWeightFix", "1.1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class CartWeightFix : BaseUnityPlugin { [HarmonyPatch(typeof(Vagon), "FixedUpdate")] private static class Vagon_FixedUpdate_Restore { [HarmonyPostfix] private static void Postfix(Vagon __instance) { if (UpdateMass == null) { return; } if (__instance.IsAttached() && AttachJoin != null) { try { object value = AttachJoin.GetValue(__instance); if (value != null) { PropertyInfo property = value.GetType().GetProperty("connectedBody"); if (property == null) { property = value.GetType().BaseType.GetProperty("connectedBody"); } if (property != null) { object value2 = property.GetValue(value, null); if (value2 != null) { Component val = (Component)((value2 is Component) ? value2 : null); if ((Object)(object)val != (Object)null && (Object)(object)val.GetComponent() != (Object)null) { return; } } } } } catch { } } try { UpdateMass.Invoke(__instance, null); } catch { } } } public const string PluginGUID = "fix.vagon.cartweightfix"; public const string PluginName = "CartWeightFix"; public const string PluginVersion = "1.1.0"; internal static MethodInfo UpdateMass; internal static FieldInfo AttachJoin; private void Awake() { //IL_005a: Unknown result type (might be due to invalid IL or missing references) BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; UpdateMass = typeof(Vagon).GetMethod("UpdateMass", bindingAttr); AttachJoin = typeof(Vagon).GetField("m_attachJoin", bindingAttr); if (UpdateMass == null) { ((BaseUnityPlugin)this).Logger.LogWarning((object)"Vagon.UpdateMass not found — cart weight fix inactive"); return; } new Harmony("fix.vagon.cartweightfix").PatchAll(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"CartWeightFix loaded — vanilla cart weight physics restored"); } }