Decompiled source of AreaTrashGrabber IL2CPP v1.0.0

AreaTrashGrabber.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AreaTrashGrabber;
using HarmonyLib;
using Il2CppScheduleOne.DevUtilities;
using Il2CppScheduleOne.Equipping;
using Il2CppScheduleOne.Interaction;
using Il2CppScheduleOne.Trash;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering.Universal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(global::AreaTrashGrabber.AreaTrashGrabber), "AreaTrashGrabber", "1.0.0", "NanobotZ", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AreaTrashGrabber")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AreaTrashGrabber")]
[assembly: AssemblyTitle("AreaTrashGrabber")]
[assembly: NeutralResourcesLanguage("en-US")]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AreaTrashGrabber
{
	public class AreaTrashGrabber : MelonMod
	{
		internal static AreaTrashGrabber Instance;

		internal static DecalProjector PickupAreaProjector;

		private MelonPreferences_Category config;

		internal MelonPreferences_Entry<float> configPickupRadius;

		internal MelonPreferences_Entry<bool> configAllowOverfilling;

		internal MelonPreferences_Entry<bool> configRemoveCapacityLimit;

		public static float PickupRadius => Instance.configPickupRadius.Value;

		public static float PickupRadiusSquared => PickupRadius * PickupRadius;

		public static bool AllowOverfilling => Instance.configAllowOverfilling.Value;

		public static bool RemoveCapacityLimit => Instance.configRemoveCapacityLimit.Value;

		public override void OnInitializeMelon()
		{
			Instance = this;
			config = MelonPreferences.CreateCategory("AreaTrashGrabber");
			config.SetFilePath("UserData/AreaTrashGrabber.cfg");
			configPickupRadius = config.CreateEntry<float>("PickupRadius", 1f, "Pickup Radius", (string)null, false, false, (ValueValidator)null, (string)null);
			configAllowOverfilling = config.CreateEntry<bool>("AllowOverfilling", false, "Allow Overfilling", (string)null, false, false, (ValueValidator)null, (string)null);
			configRemoveCapacityLimit = config.CreateEntry<bool>("RemoveCapacityLimit", false, "Remove Capacity Limit", (string)null, false, false, (ValueValidator)null, (string)null);
			((MelonBase)this).LoggerInstance.Msg("Initialized.");
		}
	}
	[HarmonyPatch(typeof(Equippable_TrashGrabber), "Update")]
	public static class Patch_EquippableTrashGrabber_Update
	{
		public static void Postfix()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)AreaTrashGrabber.PickupAreaProjector == (Object)null)
			{
				return;
			}
			if ((Object)(object)Singleton<InteractionManager>.Instance.hoveredValidInteractableObject == (Object)null)
			{
				((Component)AreaTrashGrabber.PickupAreaProjector).gameObject.SetActive(false);
				return;
			}
			TrashItem component = ((Component)Singleton<InteractionManager>.Instance.hoveredValidInteractableObject).GetComponent<TrashItem>();
			if ((Object)(object)component == (Object)null || !component.CanGoInContainer)
			{
				((Component)AreaTrashGrabber.PickupAreaProjector).gameObject.SetActive(false);
				return;
			}
			float num = Mathf.Abs(AreaTrashGrabber.PickupRadius) / 0.45f;
			AreaTrashGrabber.PickupAreaProjector.size = new Vector3(num, num, 0.5f);
			((Component)AreaTrashGrabber.PickupAreaProjector).transform.position = ((Component)component).transform.position;
			((Component)AreaTrashGrabber.PickupAreaProjector).gameObject.SetActive(true);
		}
	}
	[HarmonyPatch(typeof(Equippable_TrashGrabber), "Equip")]
	public static class Patch_EquippableTrashGrabber_Equip
	{
		public static void Postfix()
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)AreaTrashGrabber.PickupAreaProjector == (Object)null)
			{
				AreaTrashGrabber.PickupAreaProjector = Object.Instantiate<DecalProjector>(((IEnumerable<TrashBag_Equippable>)Resources.FindObjectsOfTypeAll<TrashBag_Equippable>()).FirstOrDefault().PickupAreaProjector);
				((Component)AreaTrashGrabber.PickupAreaProjector).transform.SetParent(NetworkSingleton<GameManager>.Instance.Temp);
				((Component)AreaTrashGrabber.PickupAreaProjector).transform.localScale = Vector3.one;
				((Component)AreaTrashGrabber.PickupAreaProjector).transform.forward = -Vector3.up;
				((Component)AreaTrashGrabber.PickupAreaProjector).gameObject.SetActive(false);
			}
		}
	}
	[HarmonyPatch(typeof(Equippable_TrashGrabber), "Unequip")]
	public static class Patch_EquippableTrashGrabber_Unequip
	{
		public static void Postfix()
		{
			if (!((Object)(object)AreaTrashGrabber.PickupAreaProjector == (Object)null))
			{
				((Component)AreaTrashGrabber.PickupAreaProjector).gameObject.SetActive(false);
				Object.Destroy((Object)(object)AreaTrashGrabber.PickupAreaProjector);
				AreaTrashGrabber.PickupAreaProjector = null;
			}
		}
	}
	[HarmonyPatch(typeof(Equippable_TrashGrabber), "PickupTrash")]
	public static class Patch_EquippableTrashGrabber_PickupTrash
	{
		private struct TrashItemDistance
		{
			public TrashItem item;

			public float distanceSquared;

			public TrashItemDistance(TrashItem item, float distanceSquared)
			{
				this.item = item;
				this.distanceSquared = distanceSquared;
			}
		}

		private static bool DontRun;

		public static void Postfix(Equippable_TrashGrabber __instance, TrashItem item)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			if (DontRun)
			{
				return;
			}
			try
			{
				DontRun = true;
				List<TrashItemDistance> list = new List<TrashItemDistance>();
				float pickupRadiusSquared = AreaTrashGrabber.PickupRadiusSquared;
				bool allowOverfilling = AreaTrashGrabber.AllowOverfilling;
				Enumerator<TrashItem> enumerator = NetworkSingleton<TrashManager>.Instance.trashItems.GetEnumerator();
				while (enumerator.MoveNext())
				{
					TrashItem current = enumerator.Current;
					if (!(item.GUID == current.GUID) && current.CanGoInContainer)
					{
						Vector3 val = ((Component)current).transform.position - ((Component)item).transform.position;
						float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
						if (!(sqrMagnitude > pickupRadiusSquared))
						{
							list.Add(new TrashItemDistance(current, sqrMagnitude));
						}
					}
				}
				Melon<AreaTrashGrabber>.Logger.Msg($"Picking up {list.Count + 1} trash items.");
				int num = 1;
				foreach (TrashItemDistance item2 in list.OrderBy((TrashItemDistance x) => x.distanceSquared))
				{
					__instance.PickupTrash(item2.item);
					num++;
					if (!allowOverfilling && __instance.GetCapacity() <= 0)
					{
						Melon<AreaTrashGrabber>.Logger.Msg($"Picked up only {num} items - bin is full.");
						break;
					}
				}
			}
			finally
			{
				DontRun = false;
			}
		}
	}
	[HarmonyPatch(typeof(Equippable_TrashGrabber), "GetCapacity")]
	public static class Patch_EquippableTrashGrabber_GetCapacity
	{
		internal static bool Prefix(ref int __result)
		{
			if (AreaTrashGrabber.RemoveCapacityLimit)
			{
				__result = int.MaxValue;
				return false;
			}
			return true;
		}
	}
}