Decompiled source of StopDropScattering v1.1.0

BepInEx\plugins\Vonny1412.StopDropScattering\StopDropScattering.dll

Decompiled 2 weeks ago
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
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: AssemblyCompany("Yvonne Pautz")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © Yvonne Pautz 2026")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+build.202609281420.692029cce6fe36727b56a5e930f518e74ed609a5")]
[assembly: AssemblyProduct("StopDropScattering")]
[assembly: AssemblyTitle("StopDropScattering")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace StopDropScattering
{
	[BepInPlugin("Vonny1412.StopDropScattering", "StopDropScattering", "1.1.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public class Configs
		{
			private const string Section_General = "General";

			public static void Initialize(ConfigFile Config)
			{
			}
		}

		public const string Version = "1.1.0";

		public const string ModName = "StopDropScattering";

		public const string ModGuid = "Vonny1412.StopDropScattering";

		internal static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Configs.Initialize(((BaseUnityPlugin)this).Config);
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
		}
	}
}
namespace StopDropScattering.Patches
{
	[HarmonyPatch(typeof(ItemDrop), "Awake")]
	internal static class ItemDrop_Awake_Patch
	{
		private static void Postfix(ItemDrop __instance)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)__instance) && Object.op_Implicit((Object)(object)((Component)__instance).transform))
			{
				Vector3 position = ((Component)__instance).transform.position;
				if (!(position.y < 4500f))
				{
					((MonoBehaviour)__instance).StartCoroutine(CheckIfFalling(__instance, position));
				}
			}
		}

		private static IEnumerator CheckIfFalling(ItemDrop itemDrop, Vector3 spawnPosition)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody rb = ((Component)itemDrop).GetComponent<Rigidbody>();
			if (!Object.op_Implicit((Object)(object)rb))
			{
				yield break;
			}
			Transform t = ((Component)itemDrop).transform;
			float lastY = spawnPosition.y;
			for (int i = 10; i > 0; i--)
			{
				yield return (object)new WaitForSeconds(0.5f);
				if (!Object.op_Implicit((Object)(object)itemDrop))
				{
					break;
				}
				float num = lastY - t.position.y;
				if (num <= 0.01f)
				{
					break;
				}
				if (num > 10f)
				{
					string text = ((Object)((Component)itemDrop).gameObject).name.Replace("(Clone)", "");
					Player closestPlayer = Player.GetClosestPlayer(spawnPosition, 100f);
					bool flag = Object.op_Implicit((Object)(object)ZNet.instance) && ZNet.instance.IsServer();
					if (!Object.op_Implicit((Object)(object)closestPlayer))
					{
						if (flag)
						{
							Plugin.Log.LogInfo((object)("No player found near spawn position to catch " + text));
						}
						break;
					}
					ZNetView component = ((Component)itemDrop).GetComponent<ZNetView>();
					if (Object.op_Implicit((Object)(object)component) && component.IsValid() && component.IsOwner())
					{
						if (flag)
						{
							Plugin.Log.LogInfo((object)(closestPlayer.GetPlayerName() + " catches " + text));
						}
						else if ((Object)(object)Player.m_localPlayer == (Object)(object)closestPlayer)
						{
							Plugin.Log.LogInfo((object)("Catching " + text));
						}
						rb.linearVelocity = Vector3.zero;
						rb.angularVelocity = Vector3.zero;
						rb.position = ((Component)closestPlayer).transform.position + Vector3.up;
					}
					break;
				}
				lastY = t.position.y;
			}
		}
	}
}