using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
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: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace InstantMonsterDrop;
[BepInPlugin("aedenthorn.InstantMonsterDrop", "Instant Monster Drop", "0.5.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))
{
Dbgl($"Changing death time from {__instance.m_ttl} to {destroyDelay.Value}, drop time from {__instance.m_ttl} to {dropDelay.Value}");
((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;
}
}
[HarmonyPatch(typeof(Terminal), "InputText")]
private static class InputText_Patch
{
private static bool Prefix(Terminal __instance)
{
if (!modEnabled.Value)
{
return true;
}
string text = ((TMP_InputField)__instance.m_input).text;
if (text.ToLower().Equals(typeof(BepInExPlugin).Namespace.ToLower() + " reset"))
{
((BaseUnityPlugin)context).Config.Reload();
((BaseUnityPlugin)context).Config.Save();
Traverse.Create((object)__instance).Method("AddString", new object[1] { text }).GetValue();
Traverse.Create((object)__instance).Method("AddString", new object[1] { ((BaseUnityPlugin)context).Info.Metadata.Name + " config reloaded" }).GetValue();
return false;
}
return true;
}
}
private static BepInExPlugin context;
private static ConfigEntry<bool> modEnabled;
private static ConfigEntry<bool> isDebug;
private static ConfigEntry<float> dropDelay;
private static ConfigEntry<float> destroyDelay;
private static ConfigEntry<int> nexusID;
public static void Dbgl(string str = "", bool pref = true)
{
if (isDebug.Value)
{
Debug.Log((object)((pref ? (typeof(BepInExPlugin).Namespace + " ") : "") + str));
}
}
private void Awake()
{
context = this;
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable this mod");
isDebug = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "IsDebug", false, "Enable debug");
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");
nexusID = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NexusID", 164, "Mod ID on the Nexus for update checks");
nexusID.Value = 164;
((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;
}
Dbgl("delaying dropping loot");
yield return (object)new WaitForSeconds(dropDelay.Value);
if (modEnabled.Value && nview.IsValid() && nview.IsOwner())
{
Dbgl("dropping loot");
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)
{
Dbgl("delaying destroying ragdoll");
yield return (object)new WaitForSeconds(Mathf.Max(destroyDelay.Value - dropDelay.Value, 0f));
if (modEnabled.Value && nview.IsValid() && nview.IsOwner())
{
Dbgl("destroying ragdoll");
Vector3 averageBodyPosition = ragdoll.GetAverageBodyPosition();
m_removeEffect.Create(averageBodyPosition, Quaternion.identity, (Transform)null, 1f, -1);
ZNetScene.instance.Destroy(((Component)ragdoll).gameObject);
}
}
}