Decompiled source of CartReclaim v1.0.0

BepInEx/plugins/CartReclaim.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("reclaim")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("reclaim")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("218A981A-22F6-4A6B-90DD-A1115A1385F2")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace reclaim;

[BepInPlugin("com.whale.repo.Reclaim", "CartReclaim", "1.0.0")]
public class Reclaim : BaseUnityPlugin
{
	[HarmonyPatch(typeof(PhysGrabCart), "Start")]
	public class PhysGrabCartPatch
	{
		public static void Postfix(PhysGrabCart __instance, PhysGrabObject ___physGrabObject)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: 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_00cb: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Expected O, but got Unknown
			if (__instance.isSmallCart)
			{
				return;
			}
			if ((Object)(object)___physGrabObject == (Object)null)
			{
				Debug.LogError((object)"Unable to get PhysGrabObject from PhysGrabCart");
				return;
			}
			FieldInfo fieldInfo = AccessTools.Field(((object)___physGrabObject).GetType(), "impactDetector");
			PhysGrabObjectImpactDetector val = (PhysGrabObjectImpactDetector)fieldInfo.GetValue(___physGrabObject);
			if ((Object)(object)val == (Object)null)
			{
				Debug.LogError((object)"Unable to get PhysGrabObjectImpactDetector from PhysGrabCart");
				return;
			}
			UnityEvent val2 = val.onDestroy;
			if (val2 == null)
			{
				val2 = new UnityEvent();
				fieldInfo.SetValue(___physGrabObject, val2);
			}
			MethodInfo spawnItemMethod = AccessTools.Method(typeof(PunManager), "SpawnItem", (Type[])null, (Type[])null);
			GameObject val3 = new GameObject();
			ItemVolume itemVolume = val3.AddComponent<ItemVolume>();
			Transform transform = val3.transform;
			transform.position = _cartPosition;
			transform.rotation = _cartRotation;
			val2.AddListener((UnityAction)delegate
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_cartItem == (Object)null)
				{
					Debug.LogError((object)"Unable to respawn cart. Cart item is null");
				}
				else
				{
					_ = _cartPosition;
					spawnItemMethod.Invoke(PunManager.instance, new object[2] { _cartItem, itemVolume });
				}
			});
			Debug.Log((object)"Successfully applied respawn effect to cart");
		}
	}

	[HarmonyPatch(typeof(PunManager), "TruckPopulateItemVolumes")]
	public class PunManagerPatch
	{
		public static bool Prefix(PunManager __instance, ItemManager ___itemManager)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Invalid comparison between Unknown and I4
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Invalid comparison between Unknown and I4
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			foreach (Item item in ___itemManager.purchasedItems)
			{
				if ((Object)(object)_cartItem == (Object)null && (int)item.itemType == 2 && (int)item.itemVolume == 3)
				{
					_cartItem = item;
					ItemVolume val = ___itemManager.itemVolumes.Find((ItemVolume v) => v.itemVolume == item.itemVolume);
					if ((Object)(object)val != (Object)null)
					{
						_cartPosition = ((Component)val).transform.position;
						_cartPosition.y += 1f;
						_cartRotation = ((Component)val).transform.rotation;
					}
					break;
				}
			}
			return true;
		}
	}

	private static Item _cartItem;

	private static Vector3 _cartPosition = Vector3.zero;

	private static Quaternion _cartRotation;

	private void Awake()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		new Harmony("com.whale.repo.CartReclaim").PatchAll(Assembly.GetExecutingAssembly());
		((BaseUnityPlugin)this).Logger.LogInfo((object)"C.A.R.T. R.E.C.L.A.I.M. mod loaded");
	}
}