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 GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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("realistic_recharge")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Lethal Company Realistic Recharging mod.")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fe1a3d906a5bf947864e46292f79ed716b4669e6")]
[assembly: AssemblyProduct("realistic_recharge")]
[assembly: AssemblyTitle("realistic_recharge")]
[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 realistic_recharge
{
[BepInPlugin("realistic_recharge", "realistic_recharge", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private void Awake()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
new Harmony("realistic_recharge").PatchAll(typeof(Plugin).Assembly);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin realistic_recharge is loaded!");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "realistic_recharge";
public const string PLUGIN_NAME = "realistic_recharge";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace MetalRecharging.Patches
{
[HarmonyPatch(typeof(PlayerControllerB))]
internal class InteractPerformedPatch
{
private static bool _swappingTwoHandedValue;
[HarmonyPatch("Interact_performed")]
[HarmonyPrefix]
internal static void InteractPerformedPrefix(PlayerControllerB __instance)
{
if (!((Object)(object)__instance.hoveringOverTrigger == (Object)null) && __instance.twoHanded)
{
Transform parent = ((Component)__instance.hoveringOverTrigger).transform.parent;
if (!((Object)(object)parent == (Object)null) && !(((Object)((Component)parent).gameObject).name != "ChargeStationTrigger"))
{
_swappingTwoHandedValue = true;
__instance.twoHanded = false;
}
}
}
[HarmonyPatch("Interact_performed")]
[HarmonyPostfix]
internal static void InteractPerformedPostfix(PlayerControllerB __instance)
{
if (_swappingTwoHandedValue)
{
_swappingTwoHandedValue = false;
__instance.twoHanded = true;
}
}
}
[HarmonyPatch(typeof(ItemCharger))]
internal class ItemChargerPatch
{
[HarmonyPatch("Update")]
[HarmonyPrefix]
private static bool ItemChargerUpdate(ItemCharger __instance, ref float ___updateInterval, ref InteractTrigger ___triggerScript)
{
if ((Object)(object)NetworkManager.Singleton == (Object)null)
{
return false;
}
if (___updateInterval > 1f)
{
___updateInterval = 0f;
if ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null)
{
GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
if ((Object)(object)currentlyHeldObjectServer == (Object)null || (!currentlyHeldObjectServer.itemProperties.isConductiveMetal && !currentlyHeldObjectServer.itemProperties.requiresBattery))
{
___triggerScript.interactable = false;
___triggerScript.disabledHoverTip = "(Requires battery-powered or metal item)";
}
else
{
___triggerScript.interactable = true;
}
___triggerScript.twoHandedItemAllowed = true;
return false;
}
}
___updateInterval += Time.deltaTime;
return false;
}
[HarmonyPatch("ChargeItem")]
[HarmonyPostfix]
private static void ItemChargerCharge(ItemCharger __instance, ref Coroutine ___chargeItemCoroutine)
{
GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
if ((Object)(object)currentlyHeldObjectServer != (Object)null && !currentlyHeldObjectServer.itemProperties.requiresBattery && currentlyHeldObjectServer.itemProperties.isConductiveMetal)
{
__instance.PlayChargeItemEffectServerRpc((int)GameNetworkManager.Instance.localPlayerController.playerClientId);
if (___chargeItemCoroutine != null)
{
((MonoBehaviour)__instance).StopCoroutine(___chargeItemCoroutine);
}
if (GameNetworkManager.Instance.localPlayerController.AllowPlayerDeath())
{
___chargeItemCoroutine = ((MonoBehaviour)__instance).StartCoroutine(ItemChargerDelayed(__instance, currentlyHeldObjectServer));
}
}
}
private static IEnumerator ItemChargerDelayed(ItemCharger __instance, GrabbableObject itemToCharge)
{
__instance.zapAudio.Play();
yield return (object)new WaitForSeconds(0.75f);
__instance.chargeStationAnimator.SetTrigger("zap");
GameNetworkManager.Instance.localPlayerController.KillPlayer(Vector3.zero, true, (CauseOfDeath)11, 0, default(Vector3));
}
}
}