using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
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("TurretKey")]
[assembly: AssemblyConfiguration("release")]
[assembly: AssemblyDescription("Turrets can now be disabled if you use a key on them!")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1")]
[assembly: AssemblyProduct("TurretKey")]
[assembly: AssemblyTitle("TurretKey")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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 System.Runtime.Versioning
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class RequiresPreviewFeaturesAttribute : Attribute
{
public string? Message { get; }
public string? Url { get; set; }
public RequiresPreviewFeaturesAttribute()
{
}
public RequiresPreviewFeaturesAttribute(string? message)
{
Message = message;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CallerArgumentExpressionAttribute : Attribute
{
public string ParameterName { get; }
public CallerArgumentExpressionAttribute(string parameterName)
{
ParameterName = parameterName;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CollectionBuilderAttribute : Attribute
{
public Type BuilderType { get; }
public string MethodName { get; }
public CollectionBuilderAttribute(Type builderType, string methodName)
{
BuilderType = builderType;
MethodName = methodName;
}
}
[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class CompilerFeatureRequiredAttribute : Attribute
{
public const string RefStructs = "RefStructs";
public const string RequiredMembers = "RequiredMembers";
public string FeatureName { get; }
public bool IsOptional { get; set; }
public CompilerFeatureRequiredAttribute(string featureName)
{
FeatureName = featureName;
}
}
[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
{
public string[] Arguments { get; }
public InterpolatedStringHandlerArgumentAttribute(string argument)
{
Arguments = new string[1] { argument };
}
public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
{
Arguments = arguments;
}
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class InterpolatedStringHandlerAttribute : Attribute
{
}
[EditorBrowsable(EditorBrowsableState.Never)]
[ExcludeFromCodeCoverage]
internal static class IsExternalInit
{
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ModuleInitializerAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class RequiredMemberAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[ExcludeFromCodeCoverage]
internal sealed class RequiresLocationAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class SkipLocalsInitAttribute : Attribute
{
}
}
namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class ExperimentalAttribute : Attribute
{
public string DiagnosticId { get; }
public string? UrlFormat { get; set; }
public ExperimentalAttribute(string diagnosticId)
{
DiagnosticId = diagnosticId;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
internal sealed class MemberNotNullAttribute : Attribute
{
public string[] Members { get; }
public MemberNotNullAttribute(string member)
{
Members = new string[1] { member };
}
public MemberNotNullAttribute(params string[] members)
{
Members = members;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
[ExcludeFromCodeCoverage]
internal sealed class MemberNotNullWhenAttribute : Attribute
{
public bool ReturnValue { get; }
public string[] Members { get; }
public MemberNotNullWhenAttribute(bool returnValue, string member)
{
ReturnValue = returnValue;
Members = new string[1] { member };
}
public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
{
ReturnValue = returnValue;
Members = members;
}
}
[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class SetsRequiredMembersAttribute : Attribute
{
}
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class StringSyntaxAttribute : Attribute
{
public const string CompositeFormat = "CompositeFormat";
public const string DateOnlyFormat = "DateOnlyFormat";
public const string DateTimeFormat = "DateTimeFormat";
public const string EnumFormat = "EnumFormat";
public const string GuidFormat = "GuidFormat";
public const string Json = "Json";
public const string NumericFormat = "NumericFormat";
public const string Regex = "Regex";
public const string TimeOnlyFormat = "TimeOnlyFormat";
public const string TimeSpanFormat = "TimeSpanFormat";
public const string Uri = "Uri";
public const string Xml = "Xml";
public string Syntax { get; }
public object?[] Arguments { get; }
public StringSyntaxAttribute(string syntax)
{
Syntax = syntax;
Arguments = new object[0];
}
public StringSyntaxAttribute(string syntax, params object?[] arguments)
{
Syntax = syntax;
Arguments = arguments;
}
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
[ExcludeFromCodeCoverage]
internal sealed class UnscopedRefAttribute : Attribute
{
}
}
namespace Nomnom.TurretKey
{
[HarmonyPatch(typeof(KeyItem))]
public static class KeyPatches
{
[HarmonyPatch("ItemActivate")]
[HarmonyPostfix]
private static void ItemActivatePostfix(KeyItem __instance)
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
if (!Object.op_Implicit((Object)(object)((GrabbableObject)__instance).playerHeldBy) || !((NetworkBehaviour)__instance).IsOwner)
{
return;
}
PlayerControllerB playerHeldBy = ((GrabbableObject)__instance).playerHeldBy;
Transform transform = ((Component)playerHeldBy.gameplayCamera).transform;
RaycastHit val = default(RaycastHit);
Turret val2 = default(Turret);
if (!Physics.Raycast(new Ray(transform.position, transform.forward), ref val, 3f, LayerMask.GetMask(new string[1] { "MapHazards" })) || !((Component)((RaycastHit)(ref val)).transform).TryGetComponent<Turret>(ref val2) || !val2.turretActive)
{
return;
}
ConfigEntry<float>? resetTurretTime = Plugin.ResetTurretTime;
if (resetTurretTime != null && resetTurretTime.Value > 0f)
{
((MonoBehaviour)val2).StartCoroutine(TurnOffAndOnTurret(val2, Plugin.ResetTurretTime.Value));
}
else
{
val2.ToggleTurretEnabled(false);
}
if (Random.value <= (Plugin.ChanceForKeyToBreak?.Value ?? 1f))
{
if (Object.op_Implicit((Object)(object)((GrabbableObject)__instance).itemProperties.dropSFX))
{
AudioSource tempAudio = SoundManager.Instance.tempAudio1;
((Component)tempAudio).transform.position = ((Component)val2).transform.position;
tempAudio.PlayOneShot(((GrabbableObject)__instance).itemProperties.dropSFX);
}
playerHeldBy.DespawnHeldObject();
}
}
private static IEnumerator TurnOffAndOnTurret(Turret turret, float restartTime)
{
turret.ToggleTurretEnabled(false);
yield return (object)new WaitForSeconds(restartTime);
turret.ToggleTurretEnabled(true);
}
}
[BepInPlugin("nomnom.turret-key", "Turret Key", "1.2.1")]
public sealed class Plugin : BaseUnityPlugin
{
public static ConfigEntry<float>? ChanceForKeyToBreak { get; private set; }
public static ConfigEntry<float>? ResetTurretTime { get; private set; }
private void Awake()
{
Harmony.CreateAndPatchAll(typeof(KeyPatches), "nomnom.turret-key");
Harmony.CreateAndPatchAll(typeof(TurretPatches), "nomnom.turret-key");
CreateConfig();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded TurretKey");
}
private void CreateConfig()
{
ChanceForKeyToBreak = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Chance for key to break", 1f, "Chance for key to break when used on a turret.\r\nShould be a value between 0.0 and 1.0.\r\n0.8 = 80% chance to break");
ResetTurretTime = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Reset Turret after * sec", 0f, "Set time to restart turret\r\nVanilla reset time is 5");
}
}
[HarmonyPatch(typeof(Turret))]
public static class TurretPatches
{
[HarmonyPatch("Start")]
[HarmonyPostfix]
private static void StartPostfix(Turret __instance)
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
GameObject val = new GameObject("Trigger")
{
tag = "InteractTrigger",
layer = LayerMask.NameToLayer("InteractableObject")
};
val.transform.SetParent(((Component)__instance).transform, false);
BoxCollider component = ((Component)__instance).GetComponent<BoxCollider>();
BoxCollider obj = val.AddComponent<BoxCollider>();
obj.size = component.size;
obj.center = component.center;
((Collider)obj).isTrigger = true;
val.AddComponent<InteractTrigger>().interactable = false;
}
[HarmonyPatch("Update")]
[HarmonyPostfix]
private static void UpdatePostfix(Turret __instance)
{
InteractTrigger componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<InteractTrigger>();
if (Object.op_Implicit((Object)(object)componentInChildren))
{
GrabbableObject currentlyHeldObjectServer = GameNetworkManager.Instance.localPlayerController.currentlyHeldObjectServer;
KeyItem val = default(KeyItem);
bool flag = Object.op_Implicit((Object)(object)currentlyHeldObjectServer) && ((Component)currentlyHeldObjectServer).TryGetComponent<KeyItem>(ref val);
bool turretActive = __instance.turretActive;
componentInChildren.disabledHoverTip = ((flag && turretActive) ? "Disable turret : [ LMB ]" : string.Empty);
componentInChildren.oneHandedItemAllowed = true;
}
}
[HarmonyPatch("ToggleTurretEnabledLocalClient")]
[HarmonyPostfix]
private static void ToggleTurretEnabledLocalClientPostfix(Turret __instance, bool enabled)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
if (!enabled)
{
__instance.turretModeLastFrame = (TurretMode)0;
__instance.turretMode = (TurretMode)0;
__instance.rotatingClockwise = false;
__instance.mainAudio.clip = null;
__instance.farAudio.clip = null;
__instance.berserkAudio.Stop();
if (__instance.fadeBulletAudioCoroutine != null)
{
((MonoBehaviour)__instance).StopCoroutine(__instance.fadeBulletAudioCoroutine);
}
__instance.fadeBulletAudioCoroutine = ((MonoBehaviour)__instance).StartCoroutine(__instance.FadeBulletAudio());
__instance.bulletParticles.Stop(true, (ParticleSystemStopBehavior)1);
__instance.rotationSpeed = 28f;
__instance.rotatingSmoothly = true;
__instance.turretAnimator.SetInteger("TurretMode", 0);
__instance.turretInterval = Random.Range(0f, 0.15f);
}
}
}
internal static class GeneratedPluginInfo
{
public const string Identifier = "nomnom.turret-key";
public const string Name = "Turret Key";
public const string Version = "1.2.1";
}
}