Decompiled source of CartFix v1.0.1

CartFix.dll

Decompiled 2 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Vippy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CartFix")]
[assembly: AssemblyTitle("CartFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CartFix
{
	[BepInPlugin("Vippy.CartFix", "CartFix", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal const float MassScale = 6f;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Patch();
			((BaseUnityPlugin)this).Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}
	}
}
namespace CartFix.Patches
{
	[HarmonyPatch(typeof(PhysGrabCart), "Start")]
	internal static class CartHeavyStartPatch
	{
		private static void Postfix(PhysGrabCart __instance)
		{
			Rigidbody rb = __instance.rb;
			if (!((Object)(object)rb == (Object)null))
			{
				rb.mass *= 6f;
				PhysGrabObject physGrabObject = __instance.physGrabObject;
				if ((Object)(object)physGrabObject != (Object)null)
				{
					physGrabObject.massOriginal *= 6f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PhysGrabCart), "CartMassOverride")]
	internal static class CartMassOverrideScalePatch
	{
		private static void Prefix(ref float mass)
		{
			mass *= 6f;
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "FixedUpdate")]
	internal static class CartLerpBoostPatch
	{
		private const float LerpCoefficient = 50f;

		private static void Postfix(PhysGrabObjectImpactDetector __instance)
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: 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_00d9: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0115: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			if (!__instance.inCart || __instance.isEnemy || __instance.physGrabObject.playerGrabbing.Count != 0 || (Object)(object)__instance.currentCart == (Object)null || (Object)(object)__instance.rb == (Object)null || __instance.rb.isKinematic || (Object)(object)((Component)__instance).GetComponent<PlayerTumble>() != (Object)null || ((Object)(object)GameManager.instance != (Object)null && GameManager.instance.gameMode == 1 && !PhotonNetwork.IsMasterClient))
			{
				return;
			}
			PhysGrabCart component = ((Component)__instance.currentCart).GetComponent<PhysGrabCart>();
			if (!((Object)(object)component == (Object)null))
			{
				Rigidbody rb = __instance.rb;
				Rigidbody rb2 = component.rb;
				Vector3 actualVelocity = component.actualVelocity;
				Vector3 val = (((Object)(object)rb2 != (Object)null) ? rb2.angularVelocity : Vector3.zero);
				Vector3 val2 = (((Object)(object)rb2 != (Object)null) ? rb2.worldCenterOfMass : ((Component)component).transform.position);
				Vector3 val3 = actualVelocity + Vector3.Cross(val, rb.worldCenterOfMass - val2);
				Vector3 velocity = rb.velocity;
				float y = velocity.y;
				Vector3 val4 = Vector3.Lerp(velocity, val3, 50f * Time.fixedDeltaTime);
				if (val4.y > y)
				{
					val4.y = y;
				}
				rb.velocity = val4;
			}
		}
	}
}