using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using LootableLandmines.Behavoiurs;
using LootableLandmines.Patches;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LootableLandmines")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lets you pickup and sell landmines")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+aa8ee06ebc7def84d2aa9bdad1bfea5e277f448f")]
[assembly: AssemblyProduct("LootableLandmines")]
[assembly: AssemblyTitle("LootableLandmines")]
[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 LootableLandmines
{
[BepInPlugin("procyon.lootablelandmines", "Lootable Landmines", "1.3.1")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
public Item customMineData;
public static GameObject customMinePrefab;
public const string GUID = "procyon.lootablelandmines";
public const string NAME = "Lootable Landmines";
public const string VERSION = "1.3.1";
private readonly Harmony harmony = new Harmony("procyon.lootablelandmines");
private void Awake()
{
Instance = this;
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "minemod");
AssetBundle val = AssetBundle.LoadFromFile(text);
customMineData = val.LoadAsset<Item>("Assets/CustomLandmine.asset");
CustomMine customMine = customMineData.spawnPrefab.AddComponent<CustomMine>();
((GrabbableObject)customMine).grabbable = true;
((GrabbableObject)customMine).grabbableToEnemies = true;
((GrabbableObject)customMine).itemProperties = customMineData;
((GrabbableObject)customMine).SetScrapValue(57);
Utilities.FixMixerGroups(customMineData.spawnPrefab);
NetworkPrefabs.RegisterNetworkPrefab(customMineData.spawnPrefab);
customMinePrefab = customMineData.spawnPrefab;
TerminalNode val2 = ScriptableObject.CreateInstance<TerminalNode>();
val2.clearPreviousText = true;
val2.displayText = "An explosive land mine";
Items.RegisterShopItem(customMineData, (TerminalNode)null, (TerminalNode)null, val2, 135);
harmony.PatchAll(typeof(LandminePatch));
harmony.PatchAll(typeof(PlayerControllerBPatch));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin procyon.lootablelandmines is loaded!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "LootableLandmines";
public const string PLUGIN_NAME = "LootableLandmines";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace LootableLandmines.Patches
{
[HarmonyPatch(typeof(Landmine))]
public class LandminePatch
{
private const bool Skip = false;
private const bool Continue = true;
[HarmonyPatch(typeof(Landmine), "Start")]
[HarmonyPostfix]
private static void Start(Landmine __instance)
{
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)__instance == (Object)null) && NetworkManager.Singleton.IsServer && (Object)(object)((Component)__instance).GetComponentInParent<CustomMine>() == (Object)null)
{
Debug.Log((object)"procyon.lootablelandmines - Replacing existing landmine with a custom one");
GameObject val = Object.Instantiate<GameObject>(Plugin.customMinePrefab, ((Component)__instance).transform.position, Quaternion.identity);
NetworkObject component = val.GetComponent<NetworkObject>();
component.Spawn(false);
NetworkObject componentInParent = ((Component)__instance).gameObject.GetComponentInParent<NetworkObject>();
if ((Object)(object)componentInParent != (Object)null)
{
componentInParent.Despawn(true);
}
}
}
[HarmonyPatch(typeof(Landmine), "OnTriggerEnter")]
[HarmonyPatch(typeof(Landmine), "OnTriggerExit")]
[HarmonyPrefix]
private static bool PreTriggerExit(Collider other, Landmine __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return true;
}
CustomMine component = ((Component)other).GetComponent<CustomMine>();
if ((Object)(object)component != (Object)null)
{
return false;
}
return true;
}
[HarmonyPatch(typeof(Landmine), "TriggerMineOnLocalClientByExiting")]
[HarmonyPrefix]
private static bool PreMineTrigger(Landmine __instance, ref bool ___localPlayerOnMine)
{
if ((Object)(object)__instance == (Object)null)
{
return true;
}
CustomMine componentInParent = ((Component)__instance).GetComponentInParent<CustomMine>();
if ((Object)(object)componentInParent == (Object)null)
{
return true;
}
if (!((GrabbableObject)componentInParent).hasHitGround || ((GrabbableObject)componentInParent).isHeld)
{
___localPlayerOnMine = false;
return false;
}
return true;
}
[HarmonyPatch(typeof(Landmine), "Detonate")]
[HarmonyPostfix]
public static void PostDetonate(Landmine __instance)
{
if (!((Object)(object)__instance == (Object)null) && NetworkManager.Singleton.IsServer)
{
CustomMine componentInParent = ((Component)__instance).GetComponentInParent<CustomMine>();
if ((Object)(object)componentInParent != (Object)null)
{
((GrabbableObject)componentInParent).DestroyObjectInHand(((GrabbableObject)componentInParent).playerHeldBy);
componentInParent.Cleanup();
}
}
}
[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
[HarmonyPatch(typeof(Landmine), "TriggerMineOnLocalClientByExiting")]
public static void TriggerMineOnLocalClientByExiting(Landmine instance)
{
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
public class PlayerControllerBPatch
{
[HarmonyPatch(typeof(PlayerControllerB), "BeginGrabObject")]
[HarmonyPostfix]
private static void GrabObject(PlayerControllerB __instance, GrabbableObject ___currentlyGrabbingObject)
{
if (!((Object)(object)___currentlyGrabbingObject == (Object)null) && ___currentlyGrabbingObject is CustomMine customMine)
{
customMine.EarlyGrabItem();
}
}
}
}
namespace LootableLandmines.Behavoiurs
{
internal class CustomMine : PhysicsProp
{
private Landmine _landmine;
private const float armDelay = 1.75f;
public override void Start()
{
((GrabbableObject)this).Start();
_landmine = ((Component)this).GetComponentInChildren<Landmine>();
}
public override void ItemActivate(bool used, bool buttonDown = true)
{
((GrabbableObject)this).ItemActivate(used, buttonDown);
LandminePatch.TriggerMineOnLocalClientByExiting(_landmine);
}
public override void OnHitGround()
{
((MonoBehaviour)this).Invoke("DelayedEnable", 1.75f);
}
public void EarlyGrabItem()
{
_landmine.ToggleMineEnabledLocalClient(false);
typeof(Landmine).GetField("localPlayerOnMine", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(_landmine, false);
}
private void DelayedEnable()
{
_landmine.ToggleMineEnabledLocalClient(true);
}
public void Cleanup()
{
((MonoBehaviour)this).Invoke("DelayedCleanup", 1f);
}
private void DelayedCleanup()
{
NetworkObject component = ((Component)this).GetComponent<NetworkObject>();
if ((Object)(object)component != (Object)null)
{
component.Despawn(true);
}
}
}
}