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 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("Updated Fork of InstantMonsterDrop")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace InstantMonsterDrop;
[BepInPlugin("mchangrh.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);
}
}
}