Decompiled source of InstantMonsterLootDrop v0.6.0

plugins/InstantMonsterDrop.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("InstantMonsterDrop_Fork")]
[assembly: AssemblyFileVersion("0.6.0.0")]
[assembly: AssemblyInformationalVersion("0.6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.6.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 InstantMonsterDrop
{
	[BepInPlugin("cjayride.InstantMonsterDrop", "Instant Monster Drop", "0.6.0")]
	public class BepInExPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Ragdoll), "Awake")]
		private static class Ragdoll_Awake_Patch
		{
			private static void Postfix(Ragdoll __instance, ZNetView ___m_nview, EffectList ___m_removeEffect)
			{
				if (Object.op_Implicit((Object)(object)ZNetScene.instance))
				{
					((MonoBehaviour)context).StartCoroutine(DropNow(__instance, ___m_nview, ___m_removeEffect));
				}
			}
		}

		[HarmonyPatch(typeof(Ragdoll), "DestroyNow")]
		private static class Ragdoll_DestroyNow_Patch
		{
			private static bool Prefix(Ragdoll __instance)
			{
				return !modEnabled.Value;
			}
		}

		private static BepInExPlugin context;

		private static ConfigEntry<bool> modEnabled;

		private static ConfigEntry<float> dropDelay;

		private static ConfigEntry<float> destroyDelay;

		private void Awake()
		{
			context = this;
			modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
			dropDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DropDelay", 0.01f, "Delay before dropping loot");
			destroyDelay = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DestroyDelay", 0.05f, "Delay before destroying ragdoll");
			((BaseUnityPlugin)this).Config.Save();
			if (modEnabled.Value)
			{
				Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
			}
		}

		private static IEnumerator DropNow(Ragdoll ragdoll, ZNetView nview, EffectList removeEffect)
		{
			if (dropDelay.Value < 0f)
			{
				((MonoBehaviour)context).StartCoroutine(DestroyNow(ragdoll, nview, removeEffect));
				yield break;
			}
			yield return (object)new WaitForSeconds(dropDelay.Value);
			if (modEnabled.Value && nview.IsValid() && nview.IsOwner())
			{
				Vector3 averageBodyPosition = ragdoll.GetAverageBodyPosition();
				Traverse.Create((object)ragdoll).Method("SpawnLoot", new object[1] { averageBodyPosition }).GetValue();
				((MonoBehaviour)context).StartCoroutine(DestroyNow(ragdoll, nview, removeEffect));
			}
		}

		private static IEnumerator DestroyNow(Ragdoll ragdoll, ZNetView nview, EffectList m_removeEffect)
		{
			yield return (object)new WaitForSeconds(Mathf.Max(destroyDelay.Value - dropDelay.Value, 0f));
			if (modEnabled.Value && nview.IsValid() && nview.IsOwner())
			{
				Vector3 averageBodyPosition = ragdoll.GetAverageBodyPosition();
				m_removeEffect.Create(averageBodyPosition, Quaternion.identity, (Transform)null, 1f, -1);
				ZNetScene.instance.Destroy(((Component)ragdoll).gameObject);
			}
		}
	}
}